How to write this in coffeescript?
f = (function(){ // something })();
Thanks for any tips :)
While you can just use parentheses (e.g. (-> foo)()
, you can avoid them by using the do
keyword:
do f = -> console.log 'this runs right away'
The most common use of do
is capturing variables in a loop. For instance,
for x in [1..3] do (x) -> setTimeout (-> console.log x), 1
Without the do
, you'd just be printing the value of x
after the loop 3 times.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With