onlineracoon onlineracoon - 1 year ago 125
Javascript Question

Javascript add extra argument

Lets 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 doesnt 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?

Answer Source

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

var mainArguments =;
mainArguments.push("extra data");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download