Why do generator expressions return generators?

Brendan Eich brendan at mozilla.com
Fri Sep 6 10:22:20 PDT 2013


> Allen Wirfs-Brock <mailto:allen at wirfs-brock.com>
> September 6, 2013 10:02 AM
>
> And we need to handle 'this' binding appropriately.
>
> (for (x of [1,2, 3]) this[x])
>
> can not desugar into
>
> (function*() { for (let x of [1,2, 3]) yield this[x]; })()
>
> because the 'this' binding would be wrong.

Good point, although the example in question did not use |this|, and I 
would have adapted if it had:

(function*() { for (let x of [1,2, 3]) yield this[x]; }).call(this)

Too bad that we don't have generator arrow function syntax :-P.

/be



More information about the es-discuss mailing list