Name
Object.freeze() — make an object immutable
Availability
ECMAScript 5
Synopsis
Object.freeze(o)
Arguments
oThe object to be frozen
Returns
The now-frozen argument object
o.
Description
Object.freeze() makes
o non-extensible (see Object.preventExtensions()) and makes all of its own
properties non-configurable, like Object.seal()
does. In addition, however, it also makes all non-inherited data
properties read-only. This means that new properties cannot be added
to o and that existing properties cannot
be set or deleted. Freezing an object is a permanent change: once
frozen and object cannot be unfrozen.
Note that Object.freeze()
only sets the writable attribute of data properties. Properties that
have a setter function defined are not affected. Also note that
Object.freeze() does not affect
inherited properties.
Note that this is not a method to be invoked on an object: it is a global function and you must pass an object to it.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access