Last active
February 14, 2022 16:03
-
-
Save tanner-west/280aade5f5cb448a976ebcba7f94714f to your computer and use it in GitHub Desktop.
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
function getTwoPlusTwo() { | |
return 2 + 2; | |
} | |
function* myGeneratorFunction() { | |
const sum = yield getTwoPlusTwo(); | |
console.log("two plus two equals: ", sum); | |
} | |
const g = myGeneratorFunction(); | |
console.log("calling next the first time..."); | |
const nextObject = g.next(); | |
const nextValue = nextObject.value; | |
console.log("next: ", nextObject); | |
console.log("calling next the second time..."); | |
console.log("next: ", g.next(nextValue)); | |
// calling next the first time... | |
// next: { value: 4, done: false } | |
// calling next the second time... | |
// two plus two equals: 4 | |
// next: { value: undefined, done: true } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment