Last active
March 4, 2019 02:18
-
-
Save Maccauhuru/78534b7b7c580e42f46319ed37b7a7b5 to your computer and use it in GitHub Desktop.
Function Generator Example 1
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
//create a new generator function called takeOff | |
function* takeOff(){ | |
yield "Three"; | |
yield "Two"; | |
yield "One"; | |
yield "Space Craft taking off....." | |
} | |
//assign takeOff to a funtion expression named countDown | |
const countDown = takeOff(); | |
//iterate the countDown function until you get an object with 'done:true' as a key/value pair | |
console.log(countDown.next()); //-> {value: "Three", done: false} | |
console.log(countDown.next()); //-> {value: "Two", done: false} | |
console.log(countDown.next()); //-> {value: "One", done: false} | |
console.log(countDown.next()); //-> {value: "Space Craft taking off.....", done: false} | |
console.log(countDown.next()); //-> {value: undefined, done: true} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment