Prevents the modification of attributes of existing properties, and prevents the addition of new properties.
Syntax
Object.seal(object)
Parameters
object
Required. The object on which to lock the attributes.
Return Value
The object that is passed to the function.
Exceptions
If the object argument is not an object, a TypeError exception is thrown.
Remarks
The Object.seal function does both of the following:
Makes the object non-extensible, so that new properties cannot be added to it.
Sets the
configurableattribute tofalsefor all properties of the object.When the
configurableattribute isfalse, property attributes cannot be changed and the property cannot be deleted. Whenconfigurableisfalseandwritableistrue, thevalueandwritableattributes can be changed.The
Object.sealfunction does not change thewritableattribute.For more information about how to set property attributes, see Object.defineProperty Function. To get the attributes of a property, you can use the Object.getOwnPropertyDescriptor Function.
Related Functions
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 | Yes |
The following functions return true if all of the conditions marked in the following table are true.
| Function | Object is extensible? | configurable is false for all properties? |
writable is false for all data properties? |
|---|---|---|---|
| Object.isExtensible | Yes | No | No |
| Object.isSealed | No | Yes | No |
| Object.isFrozen | No | Yes | Yes |
Example
The following example illustrates the use of the Object.seal function.
// Create an object that has two properties.
var obj = { pasta: "spaghetti", length: 10 };
// Seal the object.
Object.seal(obj);
document.write(Object.isSealed(obj));
document.write("<br/>");
// Try to add a new property, and then verify that it is not added.
obj.newProp = 50;
document.write(obj.newProp);
document.write("<br/>");
// Try to delete a property, and then verify that it is still present.
delete obj.length;
document.write(obj.length);
// Output:
// true
// undefined
// 10
Requirements
Supported in the following document modes: Internet Explorer 9 standards, Internet Explorer 10 standards, and Internet Explorer 11 standards. Also supported in Store apps (Windows 8 and Windows Phone 8.1). See Version Information.
Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards.
See Also
Object.preventExtensions Function
Object.freeze Function
Object.isExtensible Function
Object.isSealed Function
Object.isFrozen Function

