Hi,
I'm starting a documentation on the iterator protocol and wanted to ask
a few things just to be 100% sure, because some things may leave room to
ambiguities.
## Just for confirmation
First, on the relevant TC39 meeting notes [1]. It is suggested that
"Without Brendan, a champion of iterators and generators, don't have
full consensus". Later notes don't come back to this, so I imagine
Brendan agrees (upon confirmation, I'll PR the meeting notes to reflect
this for future readers).
## Iterator protocol next signature.
The meeting notes suggest the following signature for next:
next: () -> {done: boolean, value?: any}
(it's not clear if it's the iterator protocol or generator.next signature)
However, in the current draft, the IteratorNext operation takes a value
argument as passed it to the call to .next.
Also, although ES6 will not make use of that, it's possible for
user-generated iterators to accept any number of arguments.
Also, the IteratorComplete seems to survive if there is no "done"
property returned (interpreted as done: false obviously).
In the end, it looks like the broader signature of user-created
iterators is something like:
next: (value?: any, ...extraArgs) -> {done?: boolean, value?:any}
The language will never make use of the extra arguments, but
user-defined sub-protocols might. The generator protocol does use the
first argument if the generator body does.
> Always has an own property called "value"
To answer my above question, it looks like the .next signature agreed
upon is neither the iterator protocol (which seems effectively broader),
not the generator one, which as quoted always have an own value property.
David
[1]
https://github.com/rwaldron/tc39-notes/blob/master/es6/2013-03/mar-12.md#conclusionresolution-1
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss