Name
Object.freeze() — make an object immutable
Availability
ECMAScript 5
Synopsis
Object
.
freeze
(
o
)
Arguments
o
The 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.
Get JavaScript: The Definitive Guide, 6th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.