实例的参数变量是什么? [英] what is the arguments variable an instance of?

查看:117
本文介绍了实例的参数变量是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MDN表示它是"类似于对象的数组",但没有说明它是什么实例.

MDN says it is "an Array like object" but does not say what it is an instance of.

它不是HTMLCollectionNodeList.

如果我呼叫Object.prototype.toString.call(arguments),它将返回"[object Arguments]",但arguments instanceof Arguments是错误.

If I call Object.prototype.toString.call(arguments) it returns "[object Arguments]" but arguments instanceof Arguments is an error.

那么arguments的实例是什么?

推荐答案

那么实例的参数是什么?

So what is arguments an instance of?

它是Object的一个实例.似乎没有任何公共Arguments构造函数可与instanceof一起使用,以这种方式进行标识.

It's an instance of Object. There does not appear to be any public Arguments constructor that you can use with instanceof to identify it that way.

如果要唯一标识它,则:

If you want to uniquely identify it, then:

Object.prototype.toString.call(arguments) === "[object Arguments]"

是一种安全的识别方式.

is a safe way to identify it.

每个EcmaScript 6规范中的第9.4.4节arguments对象是普通对象或奇异对象.规格说明如下:

Per section 9.4.4 in the EcmaScript 6 specification, the arguments object is either an ordinary object or an exotic object. Here's what the spec says:

大多数ECMAScript函数使自变量对象可用于其 代码.根据函数定义的特征, 它的自变量对象是普通对象自变量 异物.

Most ECMAScript functions make an arguments objects available to their code. Depending upon the characteristics of the function definition, its argument object is either an ordinary object or an arguments exotic object.

异国情调 object是一个奇异对象,其数组索引属性映射到 与其关联的调用的形式参数绑定 ECMAScript函数.

An arguments exotic object is an exotic object whose array index properties map to the formal parameters bindings of an invocation of its associated ECMAScript function.

参数奇异对象具有相同的内部 插槽作为普通对象.他们也有一个[[ParameterMap]]内部 投币口.普通参数对象还具有[[ParameterMap]]内部 其值始终未定义的插槽.对于普通参数对象 [[ParameterMap]]内部插槽仅由 Object.prototype.toString(19.1.3.6)来标识它们.

Arguments exotic objects have the same internal slots as ordinary objects. They also have a [[ParameterMap]] internal slot. Ordinary arguments objects also have a [[ParameterMap]] internal slot whose value is always undefined. For ordinary argument objects the [[ParameterMap]] internal slot is only used by Object.prototype.toString (19.1.3.6) to identify them as such.

由于它是一个异国情调"的对象,因此从本质上讲它并不遵循所有正常的和预期的约定.例如,没有构造函数可以从中创建自己的对象.而且,因为没有公共构造函数,所以这也可能解释了为什么没有instanceof可以对其进行测试以唯一标识它的原因.

Since it is an "exotic" object, that essentially means it doesn't follow all the normal and expected conventions. For example, there is no constructor function from which you can create your own object. And, because there is no public constructor function, that probably also explains why there's no instanceof that you can test on it to uniquely identify it.

这篇关于实例的参数变量是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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