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

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

问题描述

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?

推荐答案

那么参数实例是什么?

So what is arguments an instance of?

它是Object 的一个实例.似乎没有任何可以与 instanceof 一起使用的公共 Arguments 构造函数来识别它.

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天全站免登陆