简体   繁体   中英

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?

The property value can be accessed by Object.isExtensible() , but where is this information stored?

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

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. If the value of the [[Extensible]] internal slot is false then additional properties may not be added to the object. In addition, if [[Extensible]] is false the value of the [[Prototype]] internal slot of the object may not be modified. Once the value of an object's [[Extensible]] internal slot has been set to false it may not be subsequently changed to 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. 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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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