Object.preventExtensions()
Prevents new properties from being added to an object.
Syntax
Object.preventExtensions(obj) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
obj | object | Yes | The object to make non-extensible. |
Returns
object — The same object, now non-extensible.
Examples
const o = Object.preventExtensions({ a: 1 });
o.b = 2;
console.log(o);
Output
{ a: 1 }
console.log(Object.isExtensible(Object.preventExtensions({})));
Output
false
Notes
The weakest of the three lock-down methods: existing properties can still be
changed or deleted, only adding new ones is blocked. `seal` and `freeze` build
on this.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 6 |
| firefox | 4 |
| safari | 5.1 |
| edge | 12 |
| node | 0.10 |