# Immutable Object
# level 1
Object.defineProperty(obj, prop, {
writable: false,
configurable: false
})
1
2
3
4
2
3
4
# level 2
Object.preventExtensions()
forbid object to creating any new property.
var myObject = {a:2};
Object.preventExtensions( myObject );
myObject.b = 3;
myObject.b; // undefined
1
2
3
4
2
3
4
# level 3
Object.seal()
= Object.preventExtensions()
+ configurable: false
Object.seal(obj)
1
# level 4
Object.freeze()
= Object.seal()
+ writable: false
Object.freeze()
1