sidgate
sidgate

Reputation: 15234

Why doesn't functions from Array work on 'arguments'?

Why can't we directly call the functions from Array on arguments?

function f(){
   var x = Array.prototype.slice.call(arguments,1);
   //var x = arguments.slice(1);  **error**
 alert(x);
}

f(1,2,3);

Update: If arguments is not an array object, then how does the Array.prototype.slice function works on an non-array object?

Upvotes: 0

Views: 57

Answers (1)

Quentin
Quentin

Reputation: 943214

Because, despite having some array-like qualities, the arguments object is not an Array.

It is defined independently of, and without reference to, Array objects.

Upvotes: 4

Related Questions