JS: Prevent Adding Property
What does object is extensible mean
It means own property can be added to the object.
Together with Property Attributes configurable and writable, they determine if property can be added, deleted, or value changed.
Parent object may be extensible
🛑 warning: if a object is not extensible, but its parent may be, so people can add properties to the parent object, and your object may still get unexpected properties, because of inheritance.
What Objects Are Extensible?
- User-defined objects are extensible, by default.
- Standard objects (e.g. Object, Array, Function, Date, etc) are extensible, by default.
- Host objects (e.g.
windows.document) may or may not be extensible.
[Object, Array, Function, String, Date, RegExp].forEach((x) => { console.assert(Reflect.isExtensible(x) === true); });