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…
Since it seems like the first thing people do is convert arguments into a
Share
My conjecture:
The concept of the
argumentsobject 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.prototypewas really basic, array objects contained only 4 methods!:toString,join,reverseandsort.I think that’s one of the major reasons about they make
argumentsto inherit fromObject.prototype, at that time those Array methods didn’t look too useful.But the
Array.prototypeobject was extended in the next versions of the standard, now on ES5, Array objects have methods such asmap,reduce,every,some, etc, that are really powerful.The last year, there was a proposal in ES5 to make
argumentsinherit fromArray.prototype, in the draft stages of the standard, but was dropped off time later.In those drafts,
argumentsinherited fromArray.prototype, but for backwards compatibility with ES3, theargumentsobject had defined two own properties,toStringandtoLocaleString, both pointing to the same methods onObject.prototype, but finally, the committee decided to keep inheriting fromObject.prototype.