Prevents the addition of new properties to an object.
SyntaxObject.preventExtensions( object )
The object that is passed to the function.
ExamplesThe following example illustrates the use of the Object.preventExtensions function.
var obj = { pasta: "spaghetti", length: 10 };
Object.preventExtensions(obj);
document.write(Object.isExtensible(obj));
document.write("<br/>");
obj.newProp = 50;
document.write(obj.newProp);
Remarks
The Object.preventExtensions function makes an object non-extensible, so that new named properties cannot be added to it. After an object is made non-extensible, it cannot be made extensible.
For information about how to set property attributes, see Object.defineProperty Function.
The following related functions prevent the modification of object attributes.
Function Object is made non-extensible configurable is set to false for each property writable is set to false for each property Object.preventExtensions Yes No No Object.seal Yes Yes No Object.freeze Yes Yes YesThe following functions return true if all of the conditions marked in the following table are true.
ExceptionsIf the object argument is not an object, a TypeError exception is thrown.
See also Other articlesMicrosoft Developer Network: Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4