Created
March 9, 2017 03:50
-
-
Save togakangaroo/1e45238a553d26f969854eba9b4d02b3 to your computer and use it in GitHub Desktop.
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
var createCounter = (startVal = 0) => { | |
let state = startVal | |
return { | |
next: () => { | |
if(state < (10 + startVal)) | |
return {value: state+=1} | |
return {done: true} | |
} | |
} | |
} | |
var counter = createCounter(5) | |
var {done, value} = counter.next() | |
while(!done) { | |
console.log(value) | |
const x = counter.next() | |
done = x.done | |
value = x.value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment