Preventing modification of Objects
There are many ways to lock an object according to your needs.
Freezing an object can be useful for representing a logically immutable data structure , especially if changing the properties of the object could lead to bad behaviour elsewhere in your application. Object.freeze(…) is shallow, this means that object values in a frozen object are still mutable.
Object.seal is a superset of Object.preventExtensions in functionality in that while it prevents tacking on of arbitrary properties to objects it also prevents altering the attributes of the properties that already exist on the object. Also, it disallows deleting properties .
Object.preventExtensions() sets the extensible attribute of o to false so that no new properties can be added to it. This is a permanent change: once an object has been made non-extensible, it cannot be make extensible again.
- What is noscript tag?
- Difference between '=', '==' and '===' operators?
- What is Browser Object Model
- How to test a string as a literal and as an object ?
- What is Associative Array? How do we use it?
- What's the Difference Between Class and Prototypal Inheritance?
- Event bubbling and Event Capturing in JavScript?
- What is the difference between .call() and .apply()?
- What is an immediately-invoked function expression?
- What Are RESTful (REpresentational State Transfer)Web Services?