How do I use CoffeeScript
to call a function with multiple functions as arguments? For example, if I wanted to compile to this JavaScript
,
outerFunction(function(innerFunction1) {
console.log('argument 1');
},
function(innerFunction2) {
console.log('argument 2');
},
argument3
);
what CoffeeScript
code would I use? Assume indents of 2 spaces, even though I used 4 to make it look better on StackOverflow
. To be honest, getting the JavaScript
indentation right is hard, too. Regardless, I have tried
outerFunction (innerFunction1) ->
console.log 'argument 1'
(innerFunction2) ->
console.log 'argument 2'
argument3
but the resulting JavaScript
had innerFunction2
be at the same level as outerFunction
, rather than as a child. Using commas did not seem to help, either. Having both functions on the same line like this:
outerFunction (innerFunction1) ->
console.log 'argument 1', (innerFunction2) ->
console.log 'argument2,
argument3
has the opposite problem: innerFunction2
becomes a child of innerFunction1
.
So how do I make multiple functions be arguments of a single function in CoffeeScript
?