How to pass two anonymous functions as arguments in CoffeScript?

I think the problem lies with using single line comments //. Single-line comments enclosed in /* .. */ seem to work fine. Here’s an equivalent example with something other than a comment.

$('element').hover(
  -> console.log("first")
  -> console.log("second")
)

Or with comments using /* .. */.

$('element').hover(
  -> /* first */
  -> /* second */
)

You can try these examples under the Try CoffeeScript tab. CoffeeScript adds a return statement to return the last expression of the function. If you wanted bare-bones functions which do nothing and don’t contain a return at the end, try:

$('element').hover(
  () ->
  () ->
)
// $('element').hover(function() {}, function() {});

Leave a Comment