JavaScript中[[prototype]]属性的双括号有什么意义? [英] What is the significance of the double brackets for the [[prototype]] property in JavaScript?

查看:151
本文介绍了JavaScript中[[prototype]]属性的双括号有什么意义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道每个JavaScript对象都有一个名为 [[Prototype]] 的内部属性。某些实现允许通过名为 __ proto __ 的属性访问它,而其他实现则不允许。围绕此属性的括号是否有任何特殊意义?

I know that every JavaScript object has an internal property called [[Prototype]]. Some implementations allow access to it via a property called __proto__ while other do not. Is there any special significance of the brackets surrounding this property?

推荐答案

这是一个对象的内部属性。来自 ECMAScript 8.6.2


此规范使用各种内部属性来定义对象值的语义。 这些内部属性不是ECMAScript语言的一部分。它们仅由出于说明目的而由此规范定义。 ECMAScript的实现必须表现得就像它以此处描述的方式在内部属性上生成和操作一样。 内部属性的名称用双方括号[[]]括起来。

This specification uses various internal properties to define the semantics of object values. These internal properties are not part of the ECMAScript language. They are defined by this specification purely for expository purposes. An implementation of ECMAScript must behave as if it produced and operated upon internal properties in the manner described here. The names of internal properties are enclosed in double square brackets [[ ]].

声明,这些内部属性不是ECMAScript语言的一部分,意味着内部属性不是可以在实际代码中使用的标识符 - 内部属性不能作为包含它们的对象的成员访问。但是,他们可能 可以通过特定的功能或属性进行访问(例如,某些浏览器非常友好,您可以设置并获取 [[Prototype]] 通过 __proto __ 属性,ES5规范允许通过 Object.getPrototypeOf进行只读访问)。

The statement, "These internal properties are not part of the ECMAScript language," means that internal properties are not identifiers that can be used in actual code -- internal properties are not accessible as members of the objects that contain them. However, they may be made accessible by particular functions or properties (e.g., some browsers are kind enough let you set and get [[Prototype]] through the __proto__ property, and the ES5 spec allows read-only access through Object.getPrototypeOf).

在单括号上使用双括号可能是为了避免与实际的括号表示法(即属性访问)。

The use of double brackets over single brackets is probably to avoid any possible confusion with actual bracket notation (i.e., property access).

这篇关于JavaScript中[[prototype]]属性的双括号有什么意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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