I've got a lot of function that act as an intermediate entry-point for other functions (i.e functions that just call other functions).
How can I call the inner function with the same arguments as the parent function without respecifying them?
var foo = function(arg1, arg2) {
fooBar(argumentsOfFoo);
}
A possible solution is passing arrays but I'd like to avoid that.
You use .apply() and the arguments object:
var foo = function(arg1, arg2) {
fooBar.apply(this, arguments);
}
In modern versions of Javascript, you can use rest parameters:
function foo(...args) {
fooBar(...args);
}
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