Skip to content

Instantly share code, notes, and snippets.

@cespare
Created April 17, 2012 00:45
Show Gist options
  • Save cespare/2402610 to your computer and use it in GitHub Desktop.
Save cespare/2402610 to your computer and use it in GitHub Desktop.
Coffeescript function with multiple callbacks
foo = (f1, f2) ->
f1()
f2()
# Doesn't work -- syntax error
# foo(-> console.log("hi from f1"), -> console.log("hi from f2"))
# Simplest way I've found to do it -- newlines added for clarity
foo(
(-> console.log("hi from f1")),
(-> console.log("hi from f2"))
)
# Most concise way -- you can leave off the parens around the last function (thanks bkad)
foo (-> console.log("hi from f1")), -> console.log("hi from f2")
@pitr
Copy link

pitr commented Feb 10, 2014

I use this in situations like this:

foo ->
  console.log('f1')
, ->
  console.log('f2')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment