Stefan Baumgartner

Web ops, performance and front-end

Calling Dynamic Functions with Dynamic Paramters

18 September 2014 by @ddprrt | Posted in: 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);

Comments? Shoot me a tweet!