I saw the following regarding javascript, object data property attributes
— Configurable: Specifies whether the property can be deleted or changed.
— Enume
configurable
and writable
are NOT representing the same thing.
configurable
means property descriptor and existence.
writable
means property value only.
A property's descriptor contains value, enumerable, configurable and writable.
scenario 1: create property by assignment
'use strict'; // non-strict mode behaves slightly different
var foo = {};
foo.bar = 1; // operated by CreateDataProperty*
// the above is the same as
Object.defineProperty(foo, 'bar', {
value: 1,
configurable: true,
writable: true,
// ...
});
CreateDataProperty
is an operation defined together with ECMAScript spec.scenario 2: create property by descriptor
'use strict'; // non-strict mode behaves slightly different
var foo = {};
Object.defineProperty(foo, 'bar', {
value: 1,
// configurable => false
// writable => false
});
foo.bar = 2; // throw TypeError: Cannot assign to read only property
Object.defineProperty(foo, 'bar', {
value: 2
// ...
}); // throw TypeError: Cannot redefine property
delete foo.bar; // throw TypeError: Cannot delete property