1

How to write somting like this in CoffeeScript

foo(function() {
    return doSomethingCompicated();
}())
3
  • That is the same as foo(doSomethingCompicated()).. why so complicated (pun intended)? Commented Nov 6, 2011 at 13:33
  • this is only example... i have annonymous function with multiple lines of code... Commented Nov 6, 2011 at 13:46
  • And the same question applies. Why the anonymous function if you're just calling it immediately? Is it a question of namespace pollution? Commented Nov 10, 2011 at 17:45

2 Answers 2

2
foo do -> doSomethingComplicated()

compiles to

foo((function() {
  return doSomethingComplicated();
})());

You could also write this:

foo do -> do doSomethingComplicated
Sign up to request clarification or add additional context in comments.

Comments

0

I won't ask why this is needed, but here is a direct translation (without do):

foo (-> doSomethingComplicated())()

Note the space after foo.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.