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 In that version of ECMAScript, the I think that's one of the major reasons about they make But the The last year, there was a proposal in ES5 to make In those drafts, |
|||||||||||||||
|
The arguments object has the very unusual feature that its array-like elements are synonyms for the local variables that hold the function arguments. For example:
I always had the impression that this "magical behaviour" is the reason why |
|||||||||||||||||
|
It's important to note that without one of the designers present, we can only really conjecture why. But we can come up with some decent reasons... here's mine: From the perspective of a function, one reason could be because you can't - obviously - actually change the arguments that were passed into you. You could change an array that represents the arguments passed into you, but the arguments as they were passed is set in stone before you ever receive execution scope. You can splice, dice and pop arrays, and if you did that to the It is similar to querystring parameters. You get a collection handed to you by the client sending the request. It's part of the request information, which is already set and done. |
|||||||||||||
|
arguments doesn't just return the arguments. It returns callee object, and the array of arguments. If it were just an array, the first element might be the callee object and be more confusing. |
|||
|