Skip to content

Instantly share code, notes, and snippets.

@winterland1989
Last active September 22, 2015 10:16
Show Gist options
  • Select an option

  • Save winterland1989/f8f12acf538aff5992f2 to your computer and use it in GitHub Desktop.

Select an option

Save winterland1989/f8f12acf538aff5992f2 to your computer and use it in GitHub Desktop.
an es5 generator...
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