Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View loopclosures.coffee
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
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
Something went wrong with that request. Please try again.