On Sat, Sep 13, 2014 at 9:46 AM, Bruno Jouhier <[email protected]> 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




>
> function* genIntegers() { var i = 0; while (true) yield i++; }
> function* genNothing() { }
>
> function doSomethingWithGenerator(g) { ... }
> function foobar(really) { doSomethingWithGenerator(really ? genIntegers()
> : genNothing()); }
>
> Bruno
>
> On Saturday, September 13, 2014 4:08:42 AM UTC+2, Ep Ga wrote:
>>
>> I just... I just find it more easier to understand ES5 than Es6... A few
>> of there new addition I can see of use, but for most I'm cloudy on... I
>> just want to be able to always use ES5 with addition to it as ES+... I like
>> the callback hell, and node have module that can be use to break it down
>> into an saner view.
>>
>> I'm ES5+.... Just won't some comfort knowing that i can use it's style
>> instead of this new syntax style....
>>
>> Generators, why do they have *? Couldn't the yield sign defined a
>> behavior of the function to a generator behavior? And even understand or
>> better yet compwthending the act of generator is not clear to me....
>>
>> And why couldn't they be a key word instead of adding a funny syntax to
>> it? Like Geneator(); and generator(); for both constructor and statment?
>>
>> And promise???
>>
>> I just.... Anyone care to give a feedback?
>>
>>  --
> 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/e1ca9baa-b50d-43eb-b73a-4e49cecb145d%40googlegroups.com
> <https://groups.google.com/d/msgid/nodejs/e1ca9baa-b50d-43eb-b73a-4e49cecb145d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAHfnhfpAsvy%2BV0mmwkhxpRWk8Fys1LZsxHzgZNWXae6iWPL%3D0w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to