简体   繁体   English

JavaScript对象在哪里存储它是否可扩展?

[英]Where does a JavaScript object store whether it's extensible or not?

As described in the the question, in JavaScript, where does an object store whether it's extensible or not? 如问题中所述,在JavaScript中,对象存储在哪里是否可扩展?

The property value can be accessed by Object.isExtensible() , but where is this information stored? Object.isExtensible()可以访问属性值,但是这些信息存储在哪里?

Thanks! 谢谢!

In its [[Extensible]] internal slot , which is not directly accessible from your code (but is, of course, accessible via Object.isExtensible and Reflect.isExtensible ). 在其[[Extensible]]内部插槽中 ,它不能直接从您的代码访问(当然,可通过Object.isExtensibleReflect.isExtensible访问)。

From the link: 从链接:

Every ordinary object has a Boolean-valued [[Extensible]] internal slot that controls whether or not properties may be added to the object. 每个普通对象都有一个布尔值[[Extensible]]内部插槽,用于控制是否可以将属性添加到对象中。 If the value of the [[Extensible]] internal slot is false then additional properties may not be added to the object. 如果[[Extensible]]内部插槽的值为false,则可能无法向对象添加其他属性。 In addition, if [[Extensible]] is false the value of the [[Prototype]] internal slot of the object may not be modified. 此外,如果[[Extensible]]为false ,则不能修改对象的[[Prototype]]内部插槽的值。 Once the value of an object's [[Extensible]] internal slot has been set to false it may not be subsequently changed to true . 一旦对象的[[Extensible]]内部插槽的值设置为false,它可能不会随后更改为true

Internal slots are a bit like properties, but aren't inherited and aren't accessible (directly) from program code. 内部插槽有点像属性,但不是继承的,也不能(直接)从程序代码访问。 From Object Internal Methods and Internal Slots : 对象内部方法和内部插槽

Internal slots correspond to internal state that is associated with objects and used by various ECMAScript specification algorithms. 内部插槽对应于与对象关联并由各种ECMAScript规范算法使用的内部状态。 Internal slots are not object properties and they are not inherited. 内部插槽不是对象属性,不会继承它们。 Depending upon the specific internal slot specification, such state may consist of values of any ECMAScript language type or of specific ECMAScript specification type values. 根据特定的内部插槽规范,此状态可能包含任何ECMAScript语言类型或特定ECMAScript规范类型值的值。 Unless explicitly specified otherwise, internal slots are allocated as part of the process of creating an object and may not be dynamically added to an object. 除非另有明确说明,否则内部插槽将作为创建对象的过程的一部分进行分配,并且可能无法动态添加到对象。 Unless specified otherwise, the initial value of an internal slot is the value undefined. 除非另有说明,否则内部槽的初始值为undefined值。 Various algorithms within this specification create objects that have internal slots. 本规范中的各种算法创建具有内部插槽的对象。 However, the ECMAScript language provides no direct way to associate internal slots with an object. 但是,ECMAScript语言没有提供将内部插槽与对象关联的直接方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM