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

Jason Orendorff jason.orendorff at gmail.com
Wed Jun 12 08:17:59 PDT 2013


On Tue, Jun 11, 2013 at 12:53 PM, Allen Wirfs-Brock
<allen at wirfs-brock.com>wrote:

> But, really, for-of (and Arrray.from and friends) should just accept
> either an Iterable or an Iterator with priority given to Iterable
>
> Then the above an most conveniently be coded as:
>
> function giveMeAEmptyIterator( ) {
>    return  {
>        next() {return {done: true}},
>    }
> }
>

More convenient still:

    function *giveMeAEmptyIterator() {}

This will work fine even if for-of remains as currently specified
(unconditionally calling the @@iterator method, as I think it should).

-j
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130612/151ebf55/attachment.html>


More information about the es-discuss mailing list