Linking coffee shop and jQuery

I am trying to do this in coffeescript:

$( element ).mousedown( aFunction ).mouseup( anotherFunction ); 

I am trying to work out a way to use indentation so that something like the following returns:

 $ element .mousedown aFunction .mouseup anotherFunction 

But to no avail, are there any recommendations for chaining in coffeescript?

+7
source share
2 answers

I'm sure you don't want to use parentheses, but ...

 $("#element") .mousedown(aFunction) .mouseup(anotherFunction) 

Compiles

 $("#element").mousedown(aFunction).mouseup(anotherFunction); 
+12
source

For all the other quick readers, here's the updated paid nerd answer given here .

 req = $.get('foo.html') .success (response) -> do_something() .error (response) -> do_something() 

... compiles to:

 var req; req = $.get('foo.html').success(function(response) { return do_something(); }).error(function(response) { return do_something(); }); 

It seems that a too short dog also suggested this in the comment above.

+1
source

All Articles