JS: Object.seal
Object.seal(obj)-
make a object not able to add properties nor delete properties.
- Make obj not extensible.
- Set ALL of the obj's own property's โconfigurableโ attributes to
false. - Return the modified object obj.
๐ warning: the parent object may still have properties added or deleted, thus inherit unexpected properties.
// seal a object. const jj = { p1: 1, p2: 2 }; // configurable attribute for p1 is true console.assert( Reflect.getOwnPropertyDescriptor(jj, "p1").configurable, ); Object.seal(jj); // configurable attribute for p1 is now false console.assert( Reflect.getOwnPropertyDescriptor(jj, "p1").configurable === false, ); // configurable attribute for p2 is now false console.assert( Reflect.getOwnPropertyDescriptor(jj, "p2").configurable === false, ); // jj is now not extensible console.assert( Reflect.isExtensible(jj) === false, );