I want the javascript code to be
someFunction(42, function onSuccess() {}, function onFailure() {})
Notice that while defining onSuccess and onFailure, I want to name them (not because it’s necessary, but because it documents the code). However, I can’t get coffeescript to generate this code.
For anonymous function passing I can do
someFunction(42,
->
// onsuccess code
->
// onfailure code
)
But when I tried to give names to those functions, it didn’t translated as expected to Javascript
someFunction(42,
onSuccess : ->
// onsuccess code
onFailure : ->
// onfailure code
)
translates to
someFunction(42, { onSuccess : function () {}, onFailure : function () {} })
Another try
someFunction(42,
onSuccess ->
// onsuccess code
onFailure ->
// onfailure code
)
translates to
someFunction(42, onSuccess(function () {}), onFailure(function () {}))
How do I do this?
does this work?
http://jsfiddle.net/keith_nicholas/Qdzph/
generates..
also, this might be of interest http://kangax.github.com/nfe/
and, in the coffeescript faq, it talks about why you can’t generate named functions :-
https://github.com/jashkenas/coffee-script/wiki/FAQ