Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In order to prevent the modification of another object's property through reference, you can use one of the following techniques:

  1. Object.freeze(): You can use the Object.freeze() method to prevent any change to the object and its properties. When an object is frozen, its properties cannot be added, modified, or deleted.

  2. Object.seal(): You can use the Object.seal() method to prevent any addition or deletion of properties to an object. However, it allows modification of existing properties.

  3. Object.defineProperty(): You can use the Object.defineProperty() method to create a property with specific attributes such as read-only, writable, or configurable. By setting the writable attribute to false, you can prevent any modification of that property.

By using any of these techniques, you can prevent the modification of another object's property through reference.