Code smell? Iterator prototype has iterator method that returns "this"

Michael Theriot michael.lee.theriot at
Wed Jul 27 04:31:36 UTC 2016

There are many things I still don't understand about iterators...

var iter = [].values();
iter[Symbol.iterator]() === iter;

var weirdFunction = iter[Symbol.iterator]; === iter;

var weirdInstance = new weirdFunction(); // what is this??

On Mon, Jul 25, 2016 at 10:19 AM, John Lenz <concavelenz at> wrote:

> This seems ripe for misuse:  you don't want two "owners" for the same
> iterator calling "next" and normally, without the Iterator interface
> implementation, you would expect "iterator()" to always return an instance
> of the iterator that the caller "owned".
> Can anyone provide any historical context on why this method was added to
> the "iterator"?
> _______________________________________________
> es-discuss mailing list
> es-discuss at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list