On Monday, September 15, 2014, Ep Ga <[email protected]> wrote:

> Rick Waldron
>
> I'm speaking of this:
>
> function foo(x){
>     While(x){
>         yield x.pop();
>     }
> }


This is not valid in ES6, you cannot have a yield inside a plain function.
(There is also a typo: "While")





> var bar = Foo(["foo","bar","baz"]);


> for(;bar;) console.log(bar.next())://baz, bar, foo, undefined


> I welcome this, the ES5+ spec welcome this!
>
> But not this:
>
> function* foo(x){
>     While(x){
>         yield x.pop();
>     }
> }
>
> var bar = Foo(["foo","bar","baz"]);
>
> for(;bar;) console.log(bar.next())://{value: baz, done:false}{value: bar,
> done:false}{value: foo, done:false}{value: undefined, done:false} the done
> property will never be true consider that the while loop will not continue
> after coming across a false condition. And or the yield sign consider the
> pop() method being active on an undefined array.
>
> Returning an object that will need to be parse.


Just because you're mis-understanding how generator logic works and
you're writing intentionally wrong examples doesn't mean the feature is
broken or incorrect. If you had actually bothered to write the examples
above correctly, with the correct for-of usage, you'd see it works just
fine:

function* gen(x){
  // Don't intentionally check a value that will always be true,
  // that's not new or special to generators.
  while(x.length) {
    yield x.pop();
  }
}

for (var item of gen(["foo","bar","baz"])) {
  console.log(item);
}

"baz"
"bar"
"foo"



Rick

-- 
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/CAHfnhfromXXhQy%2BMOoBhsni5xUAf7OgidtHFJcBWtF-fD0ypyg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to