function* generateSequence() { yield 1; yield 2; return 3; } let generator = generateSequence(); let one = generator.next(); alert(JSON.stringify(one)); // {value: 1, done: false} let two = generator.next(); alert(JSON.stringify(two)); // {value: 2, done: false} let three = generator.next(); alert(JSON.stringify(three)); // {value: 3, done: true}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter