JS: Prevent Adding Property
What is Extensible?
- the Property Attribute
configurable
determines if a property can be deleted. - the Property Attribute
writable
determines if a property value can be changed.
together, 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.
console.log( [Object, Array, Function, String, Date, RegExp].every((x) => Object.isExtensible(x) ), );
γsee Object Typeγ
Check If Object is Extensible
Prevent Adding Properties
Prevent Adding/Deleting Properties
Prevent Adding/Deleting/Writing Properties
JavaScript, Prevent Change Property
JavaScript, Object and Inheritance
- JS: Object Tutorial
- JS: Object Overview
- JS: Object Type
- JS: Test is Object Type π
- JS: Determine Type of Object
- JS: Prototype and Inheritance
- JS: Prototype Chain
- JS: Object.prototype.isPrototypeOf
- JS: Get Set Prototype
- JS: Show Prototype Chain π
- JS: Create Object
- JS: Object Literal Expression
- JS: Create Object with Parent X
- JS: Prevent Adding Property
- JS: Deep Copy Object, Array π
- JS: Test Object Equality π
- JS: Add Method to Prototype
- JS: Object Object
- JS: Object Constructor
- JS: Object.prototype