Why do generator expressions return generators?

Allen Wirfs-Brock allen at wirfs-brock.com
Fri Sep 6 11:01:46 PDT 2013


On Sep 6, 2013, at 10:22 AM, Brendan Eich wrote:

>> ...
> 
> 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.

Almost as good, a arrow function with a generator comprehension as its expression body.  For example, a factory for a generator with a lexical this binding:

          c => (for (p of c) if (p in this) this[p])

not much different from a hypothetical generator arrow function and arguably better :
          c *=> {for  (p of c) if (p in this) yield this[p]}

allen







More information about the es-discuss mailing list