Passing arguments forward to another javascript function

Use .apply() to have the same access to arguments in function b, like this:

console.log = function(x) { document.write(x === undefined ? undefined : JSON.stringify(x) + "<br />"); };

function a(){
    b.apply(null, arguments);
}
function b(){
    console.log(arguments); //arguments[0] = 1, etc
}
a(1,2,3);

You can test it out here.

Leave a Comment