Is there a way of doing this without altering the function?
function foo(bar1, bar2, bar3)
{
return bar1 + bar2 + bar3;
}
var array = [1, 2, 3];
console.log(foo(array)); //6
console.log(foo.apply(null, array));
this value to the function itself. Although it doesn't make any difference, I'd say setting it to e.g. null is more semantical.foo.apply(window, array) should be the natural choice.null as the this value then it will be set to the window automatically. But since the this value doesn't matter null would be more meaningful - but after all it doesn't matter at all.
foo(array[0], array[1], array[2]);?