Skip to content

Instantly share code, notes, and snippets.

@Jxck
Created January 11, 2014 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jxck/8369377 to your computer and use it in GitHub Desktop.
Save Jxck/8369377 to your computer and use it in GitHub Desktop.
next() の挙動がよくわからない。
function* generator() {
console.log(yield 1);
console.log(yield 2);
console.log(yield 3);
return 4;
}
var g = generator();
console.log(g.next(0)); // この 0 を取る方法は?
console.log(g.next(10));
console.log(g.next(20));
console.log(g.next(30));
// $ node --harmony generator.js
// { value: 1, done: false }
// 10
// { value: 2, done: false }
// 20
// { value: 3, done: false }
// 30
// { value: 4, done: true }
@Jxck
Copy link
Author

Jxck commented Jan 12, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment