Created
January 11, 2014 10:49
-
-
Save Jxck/8369377 to your computer and use it in GitHub Desktop.
next() の挙動がよくわからない。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://twitter.com/Constellation/status/421969147929436160