Since it seems like the first thing people do is convert arguments
into a real array, I'm interested in why the Javascript language authors and implementers decided, and continue to think, that arguments
should not be a real Array
. I don't mean this as flamebait, I'm sincerely interested in the thinking behind it. Since the function is naturally being called when you're in its body, I don't think it's because the objects arguments
are referencing can change, like with some of the DOM results...
My conjecture:
The concept of the arguments
object has been on the language since the very beginning, it's even described in the ECMAScript First Edition Standard(PDF).
In that version of ECMAScript, the Array.prototype
was really basic, array objects contained only 4 methods!: toString
, join
, reverse
and sort
.
I think that's one of the major reasons about they make arguments
to inherit from Object.prototype
, at that time those Array methods didn't look too useful.
But the Array.prototype
object was extended in the next versions of the standard, now on ES5, Array objects have methods such as map
, reduce
, every
, some
, etc, that are really powerful.
The last year, there was a proposal in ES5 to make arguments
inherit from Array.prototype
, in the draft stages of the standard, but was dropped off time later.
In those drafts, arguments
inherited from Array.prototype
, but for backwards compatibility with ES3, the arguments
object had defined two own properties, toString
and toLocaleString
, both pointing to the same methods on Object.prototype
, but finally, the committee decided to keep inheriting from Object.prototype
.