Last active
August 29, 2015 14:07
-
-
Save royling/45284c2739251a8812c2 to your computer and use it in GitHub Desktop.
iterate iterator (created from generator function) in for-of/while/for loops
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* generatorFunction() { | |
// ... | |
} | |
let iterator = generatorFunction(); | |
// for-of loop | |
for (let k of iterator) { | |
// ... | |
} | |
// equivalent for loop | |
let i, k; | |
while (!(i = iterator.next()).done) { | |
k = i.value; | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment