'function *' is not mandatory

Brendan Eich brendan at mozilla.com
Sat Aug 31 12:24:32 PDT 2013


The empty-body basis case is one reason. A stronger reason is that yield 
is not a reserved identifier, and it is used in existing content, so 
function* allows contextual reservation without breaking backward 
compatibility.

Another reason is to clue readers in early, when reading in source 
order, that this function is a generator, in the case where yield usage 
in the function's body is somewhat hard to see at a glance.

/be

> Yuichi Nishiwaki <mailto:yuichi.nishiwaki at gmail.com>
> August 31, 2013 12:15 PM
> Hi all, I just found a post that the current generator syntax
> (function *) seems have decided in:
>
> https://mail.mozilla.org/pipermail/es-discuss/2011-July/015799.html
>
> According to the post, the biggest reason the star syntax is adopted
> for now is that you cannot write empty generators with star-less
> functions in a consistent simple way. But the situation has changed,
> and in the current spec (rev 17) yield* is now capable of taking any
> kind of iterator, so you can make empty generators just like
>
> ```js
> function * () {
> yield * [];
> }
> ```
>
> This looks enough good and simple at least to me. And I wonder if even
> now generators still need to be declared with 'star's. What are the
> advantages of 'star'ed generators rather than 'star'-lesses? If not
> exist, shouldn't it be removed (for the simplicity)?
>
> Thank you.
>
> --
> Yuichi Nishiwaki
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>


More information about the es-discuss mailing list