Last active
August 29, 2015 13:58
-
-
Save mstade/10012933 to your computer and use it in GitHub Desktop.
ES6 auto-rewinding iterators
This file contains hidden or 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 range(n) { | |
var i = 0 | |
return { next: step } | |
function step() { | |
if (i++ < n) return { value: i } | |
return i = 0, { done: '110%' } | |
} | |
} | |
var ten = range(5) | |
for (var n of ten) console.log(n) | |
console.log('erase and rewind') | |
for (var n of ten) console.log(n) // works |
Author
mstade
commented
Apr 7, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment