Created
May 14, 2013 00:14
-
-
Save watilde/5572624 to your computer and use it in GitHub Desktop.
yield
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 simpleGenerator(){ | |
yield "first"; | |
yield "second"; | |
yield "third"; | |
for (var i = 0; i < 3; i++) | |
yield i; | |
} | |
var g = simpleGenerator(); | |
console.log(g.next()); // "first" | |
console.log(g.next()); // "second" | |
console.log(g.next()); // "third" | |
console.log(g.next()); // 0 | |
console.log(g.next()); // 1 | |
console.log(g.next()); // 2 | |
console.log(g.next()); // StopIteration |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment