Although you can simply use parentheses (e.g. (-> foo)() , you can avoid them with the do keyword:
do f = -> console.log 'this runs right away'
The most common use of do is to capture variables in a loop. For example,
for x in [1..3] do (x) -> setTimeout (-> console.log x), 1
Without do you simply print the value of x after the loop 3 times.
Trevor Burnham Apr 09 '11 at 19:50 2011-04-09 19:50
source share