The ES6 iteration protocol
brendan at mozilla.org
Mon Apr 6 21:55:15 UTC 2015
Axel Rauschmayer wrote:
> There are two different aspects:
> 1. If you get an iterable, it sometimes matters whether iteration
> restarts when you ask the iterable for an iterator.
Rather, if you have an object o and o[Symbol.iterator]() === o then you
have an iterator.
> 2. Self-iterability is how iterators turn themselves into iterables so
> that constructs that work with iterables can be used. It also enables
> generators to play two roles: generator methods can implement
> `[Symbol.iterator]` and generator functions can implement
> iterable-returning functions.
I'm not clear on what 2 means. Generator functions definitely return
generator-iterators when called. A generator function gf does not have a
gf[Symbol.iterator] property, though.
> In this particular case, I’m interested in #1. I probably have to come
> up with a better term for it.
Yes, "singleton" is the wrong word. Perhaps you want "iterator"? :-P
More information about the es-discuss