PavlidisLab / Gemma

Genomics data re-analysis
Apache License 2.0
22 stars 6 forks source link

Use arrow functions instead of createDelegate(this) #884

Open arteymix opened 11 months ago

arteymix commented 11 months ago

We often use createDelegate(this) in JavaScript so that the current object inside a function is the one where the function was declared. This is a peculiarity of JavaScript because this is not lexically obtained.

var that = this;
var callback = (function() {
    assert this === that;
}).createDelegate(this);

In recent ECMAScript standard, this can be translated in the more readable arrow function.

var callback = () => {
    assert this === that;
}

This might require #754 so we can get Babel support to transpile arrow functions on older browsers.

arteymix commented 11 months ago

I noticed that this is an ExtJS-supplied feature, createDelegate is not a standard method, so it's added by editing the prototype of Function. Nevertheless, this workaround is not necessary.