JavaScript 对象存储在哪里,是否可扩展?
Where does a JavaScript object store whether it's extensible or not?
如问题中所述,在 JavaScript 中,无论是否可扩展,对象存储在哪里?
属性 值可以通过 Object.isExtensible()
访问,但此信息存储在哪里?
谢谢!
在其 [[Extensible]]
internal slot, which is not directly accessible from your code (but is, of course, accessible via Object.isExtensible
and Reflect.isExtensible
).
来自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.
内部槽有点像属性,但不是继承的,也不能(直接)从程序代码访问。来自 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.
如问题中所述,在 JavaScript 中,无论是否可扩展,对象存储在哪里?
属性 值可以通过 Object.isExtensible()
访问,但此信息存储在哪里?
谢谢!
在其 [[Extensible]]
internal slot, which is not directly accessible from your code (but is, of course, accessible via Object.isExtensible
and Reflect.isExtensible
).
来自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.
内部槽有点像属性,但不是继承的,也不能(直接)从程序代码访问。来自 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.