Object.isSealed()
时间: 2024-05-01 11:16:46 浏览: 92
The `Object.isSealed()` method is used to determine whether an object is sealed or not. A sealed object is one whose properties cannot be added, deleted or changed in any way.
The `isSealed()` method returns a boolean value, `true` if the object is sealed, and `false` if it is not sealed.
Example:
```
const obj1 = {
prop1: 'value1',
prop2: 'value2'
};
Object.seal(obj1);
console.log(Object.isSealed(obj1)); // true
obj1.prop1 = 'new value';
console.log(obj1.prop1); // 'new value'
delete obj1.prop2;
console.log(obj1.prop2); // 'value2'
```
In the above example, the `obj1` object is sealed using the `Object.seal()` method. Then, the `Object.isSealed()` method is used to check whether the object is sealed or not. It returns `true` because the object is sealed.
After that, an attempt is made to change the value of `prop1` and delete `prop2`, but these operations have no effect on the object because it is sealed.
阅读全文