seal
The seal function recursively seals an object, preventing the addition or removal of properties.
Syntax
typescript
seal(obj): objectParameters
| Name | Type | Description |
|---|---|---|
obj | object | Object to be sealed. |
Return
| Type | Description |
|---|---|
object | Returns the sealed object. |
Examples
typescript
const obj = { a: 1, b: { c: 2 } };
seal(obj);
// obj and obj.b cannot have properties added or removedNotes
- Internally uses
Object.sealrecursively. - Existing properties can still be modified, but not added or removed.
- Useful for protecting data structures from structural changes.
