Ensure the callback is a function, and then invoke it.
function myFunction(arg1, arg2, callback){
// do something
typeof callback == "function" && callback();
}
If you want more control over invoking it, use call()
, apply()
, bind()
(whatever achieves your goal).