I found myself using a weird way to add callback functions to my functions and I was wondering if there is a more generic way to add callbacks to functions, best case I would ha
I prefer a formal parameter:
var myFunc = function(obj, callback) {
...
}
This way it makes it obvious that there is a callback. You also don't have to mess around with the arguments
object; you can just check to see if callback
is undefined
, and then check to see if it is of the appropriate type (Function
).