HomeArticles

Calling Dynamic Functions with Dynamic Paramters

Stefan Baumgartner

Stefan on Mastodon

More on 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);

More articles on JavaScript

Stay up to date!

3-4 updates per month, no tracking, spam-free, hand-crafted. Our newsletter gives you links, updates on fettblog.eu, conference talks, coding soundtracks, and much more.