Created
January 6, 2016 16:13
-
-
Save amoilanen/db9c962d11306f64631c to your computer and use it in GitHub Desktop.
Yielding generator from a generator: seemless to the client code
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* func1() { | |
var y = yield 'b'; | |
console.log('y = ', y); | |
return 'c'; | |
} | |
function* func() { | |
var x = yield 'a' | |
console.log("x = ", x); | |
var z = yield* func1(); | |
console.log("z = ", z); | |
return 'd'; | |
} | |
var i = 0; | |
var it = func(); | |
var next = it.next(); | |
while (!next.done) { | |
console.log(next); | |
next = it.next(i++); | |
} | |
//Object { value="a", done=false} | |
//x = 0 | |
//Object { value="b", done=false} | |
//y = 1 | |
//z = c | |
//Object { value="d", done=true} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment