Last active
April 2, 2016 15:54
-
-
Save hadronzoo/4ba945cfb5073cceb0d5ed90309f6e23 to your computer and use it in GitHub Desktop.
Generator Example
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
g = generator(0) | |
=> [Function] | |
g() | |
=> 0 | |
g() | |
=> 1 | |
g() | |
=> 2 |
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
const generator = (start) => { | |
let x = start - 1; | |
return () => x = x + 1; | |
}; |
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
var generator = function generator(start) { | |
var x = start - 1; | |
return function () { | |
return x = x + 1; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment