Retrieving generator references
brendan at mozilla.org
Sat Nov 22 20:03:28 PST 2014
Axel Rauschmayer wrote:
> As an aside, I still feel that two concerns are mixed in a generator
> * The creation of the generator object. This is where the generator
> function is like a constructor and where you’d expect `this` to refer
> to the generator object.
Nope, not a constructor (and if you don't call with 'new', what is
'this', pray tell?).
> * The behavior. This is where the generator function is like a real
> A result of this mixing of concerns is that using `next()` to start a
> generator feels slightly off and that the argument of that first
> `next()` invocation is completely ignored.
We've discussed a special generator head form to declare that name, but
not for ES6. For now it's Pythonic, except we decided not to throw if
the initial .next call passes a non-undefined value.
> Alas, I have no idea how to disentangle these concerns, but it would
> be nice if we were able to.
We're not changing generators at this point, but Nicholas's request for
a way to reference the running generator-iterator instance is worth
discussing more. It can't and shouldn't be 'this'. Does it violate POLA
to provide (via another special form) for all generators? Users can
provide their own bindings as noted, so is it a big problem?
I think the task.js reference, and ES7 async/await, point to a better
direction: use helpers (libraries now, syntax soon) to automate harder
and avoid the need for the "me" reference.
More information about the es-discuss