You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If using declared in header of for-of loop variable in closure, placed in this loop, keyword "this" in that closure becomes equal to global object.
varservant={sayNumbers(){for(letnumberof[1,2,3]){(()=>{number;//without number reference "this" is rightconsole.log(this);//window})();}}}servant.sayNumbers();
This code is compiled into
varservant={sayNumbers: function(){varS_ITER$0=typeofSymbol!=='undefined'&&Symbol&&Symbol.iterator||'@@iterator';varS_MARK$0=typeofSymbol!=='undefined'&&Symbol&&Symbol["__setObjectSetter__"];functionGET_ITER$0(v){if(v){if(Array.isArray(v))return0;varf;if(S_MARK$0)S_MARK$0(v);if(typeofv==='object'&&typeof(f=v[S_ITER$0])==='function'){if(S_MARK$0)S_MARK$0(void0);returnf.call(v);}if(S_MARK$0)S_MARK$0(void0);if((v+'')==='[object Generator]')returnv;}thrownewError(v+' is not iterable')};var$D$0;var$D$1;var$D$2;var$D$3;$D$3=([1,2,3]);$D$0=GET_ITER$0($D$3);$D$2=$D$0===0;$D$1=($D$2 ? $D$3.length : void0);for(varnumber;$D$2 ? ($D$0<$D$1) : !($D$1=$D$0["next"]())["done"];){number=($D$2 ? $D$3[$D$0++] : $D$1["value"]);(function(number){varthis$0=this;(function(){number;console.log(this$0);//window})();})(number);};$D$0=$D$1=$D$2=$D$3=void0;}}servant.sayNumbers();
And all works fine if function, closing "number" variable, is called via "call" method with definition of "this".
The text was updated successfully, but these errors were encountered:
If using declared in header of for-of loop variable in closure, placed in this loop, keyword "this" in that closure becomes equal to global object.
This code is compiled into
And all works fine if function, closing "number" variable, is called via "call" method with definition of "this".
The text was updated successfully, but these errors were encountered: