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

Axel Rauschmayer axel at
Sun Jun 9 00:17:03 PDT 2013

> It seems easy enough to define a class that has a @@iterator() {return this} method and then to subclass class it for you specific Iterables.

One more thing that might be problematic with the current approach: If you create combinators for iterators (similar to Python’s itertools [1]) then the returned iterators also need to implement this pattern. Otherwise, for-of couldn’t iterate over them. Example:

    for(let elem of filter(keys(myObj), x => x.length > 0)) {

Thus, the pattern becomes the norm instead of the exception. Then again, maybe that’s not a big deal, either.


Dr. Axel Rauschmayer
axel at


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list