Questions/issues regarding generators

Andreas Rossberg rossberg at
Thu Mar 7 22:40:26 PST 2013

On 7 March 2013 22:30, Erik Arvidsson <erik.arvidsson at> wrote:
> One more thing worth pointing out is that a singleton does not work
> due to "return e" in generators needs to signal an end to iteration
> with a value. The wiki does this be creating a new object with a
> "value" property and [[Class]] set to "StopIteration"

Yes, to clarify, I did not talk about using a singleton, but about a
an instance of the StopIteration class, just like in the wiki.

> Instead of returning a singleton we can return an object with two
> fields, {value: v, done: b} and when we see a "return e" in a
> generator this becomes {value: e, done: true}.

Sure, if there is hope for getting consensus on an Either-type like
approach, then I would definitely prefer that over what I suggested!


More information about the es-discuss mailing list