I think it is an old Javascript behavior (Crockford said it is a design error) that inside a function, arguments
is like an array, except it is not a real array, so array methods cannot be invoked on it:
function foo() { console.log(arguments.slice(1)) } // won't work
foo(1,2,3);
And I just tried it on the latest Firefox and Chrome, and it won't work on both. So we may have to use
function foo() { console.log(Array.prototype.slice.call(arguments, 1)) }
foo(1,2,3);
But why not make arguments
a real array in the modern JavaScript? There probably shouldn't be any program that depends on arguments
not being a real array? What might be a reason not to make it a real array now?
One reason I can think of is, if programmers start treating it as an array, then the code won't work in older browsers, but there are other things in ECMA-5 that won't work in older browsers too.