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

John Lenz concavelenz at gmail.com
Mon Jul 25 23:28:13 UTC 2016


I understand the way it is used, but I don't understand why.   "for-of"
could have been spec'd to take either an Iterable (an object with an
[Symbol.iterator] method) or an Iterator.  Or just an Iterable.

On Mon, Jul 25, 2016 at 8:38 AM, Boris Zbarsky <bzbarsky at mit.edu> wrote:

> 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.
>
> -Boris
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160725/4da394e0/attachment.html>


More information about the es-discuss mailing list