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

Axel Rauschmayer axel at rauschma.de
Sat Jun 8 22:34:23 PDT 2013


I can’t find the rationale as to why that isn’t allowed. Is it because iterators can’t be recognized as safely as iterables?

If we did enable for-of (and Array.from) for iterators, we would get two advantages:

- Generators would not need to have a method @@iterator.
- Many functions actually return iterators, but have to turn them into iterables (by adding a method @@iterator that returns `this`) to work with for-of.

Axel

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130609/81daf600/attachment.html>


More information about the es-discuss mailing list