HomeArticles

Calling Dynamic Functions with Dynamic Paramters

JavaScript

Useful for wrapper APIs or communicating with external interfaces:

function callFunction(fn) {
this[fn].apply(this, Array.prototype.slice.call(arguments, 1));
}

callFunction("alert", "It works");
callFunction("setTimeout", function() {
alert("Timeout after 5s");
}, 5000);

Related Articles