There are two approaches you can take: the best "literal" translation into CoffeeScript (in my opinion)
req = $.get('foo.htm') .success((response) ->
Another approach is to move the built-in functions "outline", a style that Jeremy Ashkenas (creator of CoffeeScript) usually prefers non-trivial function arguments:
onSuccess = (response) -> # doSomething onError = -> # doSomething req = $.get('foo.htm').success(onSuccess).error(onError)
The latter approach tends to be more readable if the success and error callbacks are several lines long; the first is great if they are only 1-2 liners.
Trevor Burnham Feb 28 '11 at 16:18 2011-02-28 16:18
source share