Yes. In current versions of JS you can use:
app[func]( ...args );
Users of ES5 and older will need to use the .apply()
method:
app[func].apply( this, args );
Read up on these methods at MDN:
var args = [ 'p0', 'p1', 'p2' ];
function call_me (param0, param1, param2 ) {
// ...
}
// Calling the function using the array with apply()
call_me.apply(this, args);
And here a link to the original post that I personally liked for its readability
app[func].apply(this, args);
You might want to take a look at a similar question posted on Stack Overflow. It uses the .apply()
method to accomplish this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With