为什么不是函数的参数对象在Javascript数组? [英] Why isn't a function's arguments object an array in Javascript?

查看:119
本文介绍了为什么不是函数的参数对象在Javascript数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于人们似乎做的是转换参数的第一件事成为一个真正的数组,我感兴趣的是,为什么Javascript语言的作者和实施者决定,并继续想,参数应的的是一个真正的阵列。我不为flamebait这个意思,我是在它背后的思想真诚关心。因为当你在它的身上是功能自然被调用,我不认为这是因为对象参数引用都可以改变,像一些DOM结果...

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...

推荐答案

我的猜想:

参数对象一直从一开始语言的概念,它甚至在的 ECMAScript的第一版标准 <子>(PDF)。

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).

在该版本的ECMAScript,的 Array.prototype 真的很基本的,数组对象包含的只有4种方法的:<!code >的toString ,加入逆转排序

In that version of ECMAScript, the Array.prototype was really basic, array objects contained only 4 methods!: toString, join, reverse and sort.

我认为这是主要的原因之一,对他们做出参数的Object.prototype 继承,在那这些时间Array方法没看太的有用

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.

Array.prototype 对象扩大标准的下一个版本,现在ES5,Array对象有方法,如地图减少每个部分等,是的真正强大

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.

过去的一年,有在ES5的建议,使参数 Array.prototype 继承,在该标准草案阶段,但时间后下车。

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.

在这些草案,参数 Array.prototype 继承的,但对于ES3,向后兼容的参数对象已经定义了两个自己的属性,的toString 的toLocaleString ,无论是指着的Object.prototype 同样的方法,但最后,委员会决定继续从的Object.prototype 继承。

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.

这篇关于为什么不是函数的参数对象在Javascript数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆