Re: Why can’t for-of be applied to iterators?

Andreas Rossberg rossberg at
Tue Jun 11 06:17:26 PDT 2013

On 11 June 2013 14:50, Tab Atkins Jr. <jackalmage at> wrote:
> On Tue, Jun 11, 2013 at 2:08 AM, Axel Rauschmayer <axel at> wrote:
>> And it becomes harder to distinguish the interfaces, should you
>> need to [1]. 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.

That makes a terrible API, though. I think Axel has a valid point that
the distinction between iterators and iterables is fuzzy enough to be
more confusing and error-prone than useful.


More information about the es-discuss mailing list