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

Boris Zbarsky bzbarsky at
Mon Jul 25 15:38:14 UTC 2016

On 7/25/16 11:19 AM, John Lenz wrote:
> Can anyone provide any historical context on why this method was added
> to the "iterator"?

The idea is that you can do this:

   for (var something of myarray.entries())

and similar for other iterator-returning methods.  The way for-of works 
is that it will try to call iterator() on the thing to the right of the 
"of", which in this case is an Iterator instance.


More information about the es-discuss mailing list