I want to do what setTimout does, manually, with no timeout.
setTimeout(function,0,args);
Just call a function and pass it an array of arguments, without knowing or caring how many arguments were there.
Basically I want to proxy the function call through another function.
I'm bad with terminology, sorry.
Method 1: Using the apply() method: The apply() method is used to call a function with the given arguments as an array or array-like object. It contains two parameters. The this value provides a call to the function and the arguments array contains the array of arguments to be passed.
Example: var fn = function() { console. log(arguments); } var args = [1,2,3]; fn(args); I need arguments to be [1,2,3] , just like my array.
You can access specific arguments by calling their index. var add = function (num1, num2) { // returns the value of `num1` console.
function f(a, b, c) { return a + b + c; }
alert(f.apply(f, ['hello', ' ', 'world']));
In ES6:
function myFunc(a, b, c){
console.log(a, b, c);
}
var args = [1, 2, 3];
myFunc(...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