On Monday, September 15, 2014 2:51:17 AM UTC+2, Rick Waldron wrote: > > > > On Sat, Sep 13, 2014 at 9:46 AM, Bruno Jouhier <[email protected] > <javascript:>> wrote: > >> Generators have a * because it is sometimes desirable to be able to >> create a generator that does not yield. Consider the following: >> > > That's not why "function *" exists. The new syntactic form exists as a > means of creating a safe way to introduce `yield` as a special special form > keyword; currently `yield` is a valid identifier in any global or function > code. Take a look at the following: > > function foo() { > var yield = 1; > return yield; > } > > That's completely valid in non-strict code: > http://jsfiddle.net/rwaldron/16hg19cd/ If ES6 decided to risk the path > that SpiderMonkey took for JS1.7/1.8 then any code that used the word > `yield` as an identifier would suddenly stop working as intended. Providing > a new syntactic boundary prevents that from happening: no code can possibly > exist of this form or within this form, therefore nothing can be broken by > its addition. A second reason is that "function *" provides a syntactic > mechanism to clearly denote that this function declaration or expression is > in fact defining a generator. > > Rick >
Right. I forgot about the syntax issue. But it's not just syntactically useful, it is also semantically useful. -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/306faad2-b337-4c42-a87c-76ec744d6348%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
