I can’t find out how to make a function that calls another function at the end.
I want to be able to do something like this:
book.save (err) ->
MyFunc param1, param2, (callbackParam) ->
# some code using callbackParam
MyFunc = (param1, param2) ->
# some other code that defines callbackParam
?.call(callbackParam)
What has to be called and how does it receive the data?
If you want to call
MyFuncas:Then it should look like this:
And if you want to make the
callbackoptional:And if you want to supply a specific
@(AKAthis), then you’d usecallorapplyjust like in JavaScript:The
(callbackParam) -> ...stuff is just a function literal that acts like any other parameter, there’s no special block handling like in Ruby (your tags suggest that Ruby blocks are the source of your confusion).