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

Tab Atkins Jr. jackalmage at gmail.com
Mon Jul 25 23:31:26 UTC 2016


On Mon, Jul 25, 2016 at 4:28 PM, John Lenz <concavelenz at gmail.com> wrote:
> 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.

Not just for-of, but the whole rest of the world (in particular,
anything that directly consumes iterables) would also have to make
that distinction.  Much easier to just let everyone pretend that an
iterator is iterable, so you can use a common API between the two
types.  (Also, Python already worked this way, and a lot of JS
iterator details were copied from Python originally.)

~TJ


More information about the es-discuss mailing list