Created
September 30, 2020 05:07
-
-
Save mu-hun/7c8af16ff33699ab4b1583ab95161710 to your computer and use it in GitHub Desktop.
YDKJS generator example
This file contains 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
let z = 1; | |
function *foo() { | |
const x = yield 2; | |
z++ | |
const y = yield (x*z) | |
console.log(x, y, z) | |
} | |
const it_first = foo() | |
const it_second = foo() | |
let first_value = it_first.next().value; | |
console.log(first_value) | |
let second_value = it_second.next().value | |
console.log(second_value) | |
first_value = it_first.next(second_value * 10) | |
// const x = yield | |
// .value = x*z | |
.value; | |
console.log(first_value) | |
second_value = it_second.next(first_value * 5).value | |
console.log(second_value) | |
it_first.next(second_value / 2) | |
it_second.next(first_value / 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment