Last active
September 22, 2015 10:16
-
-
Save winterland1989/f8f12acf538aff5992f2 to your computer and use it in GitHub Desktop.
an es5 generator...
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
| generator = (fn) -> | |
| nexts = [] | |
| fn (next) -> | |
| if (x = nexts.indexOf next) != -1 | |
| nexts.push x | |
| else nexts.push next | |
| step = 0 | |
| next: -> | |
| next = nexts[step++] | |
| if next != undefined | |
| if (typeof next) == 'number' | |
| step = next | |
| nexts[step++]() | |
| else next() | |
| else undefined | |
| fakeGen = generator (next) -> | |
| next knot = -> '月曜日' | |
| next -> '水曜日' | |
| next -> '水曜日' | |
| for i in [1..4] then do (i=i) -> | |
| next -> i | |
| next knot | |
| for i in [1..100] | |
| console.log fakeGen.next() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment