Name
Object.preventExtensions() — don’t allow new properties on an object
Availability
ECMAScript 5
Synopsis
Object
.
preventExtensions
(
o
)
Arguments
o
The object that is to have its extensible attribute set
Returns
The argument object o
.
Description
Object.preventExtensions()
sets the extensible attribute of
o
to false so that no new properties can
be added to it. This is a permanent change: once an object has been
made non-extensible, it cannot be make extensible again.
Note that Object.preventExtensions()
does not affect
the prototype chain, and a nonextensible object can still gain new
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.