javascript generator value of this -


what value of this in javascript generators in javascript? in below code, both comparisons return false, , when .tosource(), this appears empty object. references ecma or mdn docs helpful, wasn't able find in either.

function thisgenerator(){     while(1)         yield this; }  var gen=new thisgenerator(); alert(gen.next()==thisgenerator); alert(gen.next()==gen); 

this still obeys normal rules. considering, global scope window:

var gen = (function() { yield this; })(); gen.next() === window // true var gen = (function() { "use strict"; yield this; })(); gen.next() === undefined // true 

in quirks mode, this in unbound functions global scope (which happens window), while in strict mode undefined.

ps: when calling function bound, still usual:

var o = { foo: function() { yield this; } }; o.foo().next() === o // true var o = {}; function foo() { yield this; }; foo.call(o).next() === o // true 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -