Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
65
rated 0 times [  71] [ 6]  / answers: 1 / hits: 33348  / 12 Years ago, wed, november 28, 2012, 12:00:00

Let's take a look at this code:


var mainFunction = function() {
altFunction.apply(null, arguments);
}

The arguments that are passed to mainFunction are dynamic -- they can be 4 or 10, doesn't matter. However, I have to pass them through to altFunction AND I have to add an EXTRA argument to the argument list.


I have tried this:


var mainFunction = function() {
var mainArguments = arguments;
mainArguments[mainArguments.length] = 'extra data'; // not +1 since length returns "human" count.

altFunction.apply(null, mainArguments);
}

But that does not seem to work. How can I do this?


More From » javascript

 Answers
6

arguments is not a pure array. You need to make a normal array out of it:



var mainArguments = Array.prototype.slice.call(arguments);
mainArguments.push(extra data);

[#81742] Tuesday, November 27, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kayden

Total Points: 546
Total Questions: 102
Total Answers: 95

Location: Virgin Islands (U.S.)
Member since Fri, Mar 4, 2022
2 Years ago
;