Last active
July 1, 2022 15:14
-
-
Save nathansmith/585ef92efc579914492e1c03798a5885 to your computer and use it in GitHub Desktop.
Silly JS 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
/* | |
Code snippet from this tweet. | |
https://twitter.com/nathansmith/status/1542887226803101697 | |
*/ | |
// Generator function. | |
function* dealWithIt() { | |
// Step 1. | |
yield '🙂'; | |
// Step 2. | |
return '😎'; | |
} | |
// Get instance. | |
const emoji = dealWithIt(); | |
// {value: '🙂', done: false} | |
console.log(emoji.next()); | |
// {value: '😎', done: true} | |
console.log(emoji.next()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment