Re: Why can’t for-of be applied to iterators?
Tab Atkins Jr.
jackalmage at gmail.com
Tue Jun 11 05:50:35 PDT 2013
On Tue, Jun 11, 2013 at 2:08 AM, Axel Rauschmayer <axel at rauschma.de> wrote:
> On the other hand, turning every iterator into an iterable puts the burden
> on people implementing iterators: they have to implement the iterable
That's... not really a burden. It's literally just adding an
@@iterator method whose body is "return this;". It's the right place
to put the burden, too - manual iterator authors are much, much fewer
than for-of users.
> And it becomes harder to distinguish the interfaces, should you
> need to . IMO, the purity argument also counts: this technique implies
> that iterators are a subset of iterables, but that isn’t true: For
> iterables, each invocation of `iterator` creates a new object, for
> iterators, it doesn’t.
As noted in the first comment, it's trivial to check for the
difference in all well-behaved cases by just seeing if "obj ===
obj[iterator]()" is true or false.
More information about the es-discuss