Skip to content

Instantly share code, notes, and snippets.

@AlexJWayne
Created November 7, 2011 19:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexJWayne/c8329fdec424de9c57ca to your computer and use it in GitHub Desktop.
Save AlexJWayne/c8329fdec424de9c57ca to your computer and use it in GitHub Desktop.
ary = [1..3]
# immediate 1
# immediate 2
# immediate 3
for i in ary
console.log "immediate #{i}"
# functions 3
# functions 3
# functions 3
fns = for i in ary
-> console.log "functions #{i}"
fn() for fn in fns
# functions with closure 1
# functions with closure 2
# functions with closure 3
fns = for i in ary
do (i) ->
-> console.log "functions with closure #{i}"
fn() for fn in fns
# deferred 3
# deferred 3
# deferred 3
for i in ary
setTimeout ->
console.log "deferred #{i}"
, 1000
# deferred with closure 1
# deferred with closure 2
# deferred with closure 3
for i in ary
do (i) ->
setTimeout ->
console.log "deferred with closure #{i}"
, 1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment