Why do generator expressions return generators?

Allen Wirfs-Brock allen at wirfs-brock.com
Fri Sep 6 10:02:08 PDT 2013


On Sep 6, 2013, at 9:06 AM, Brendan Eich wrote:

>> Domenic Denicola <mailto:domenic at domenicdenicola.com>
>> ...
> 
>> Why not just make them sugar for creating custom iterable-iterators without shallow coroutine capabilities?
> 
> Because we need the shallow continuation to hold the implicitly declared let bindings induced by the for heads.

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.

Allen


More information about the es-discuss mailing list