the 6th Chapter object-oriented ProgrammingTypes of Properties
There are two properties of objects in JS, data properties and accessor properties (accessor property), attributes of which have their own properties (Arrribute), which can be understood as properties about attributes.
The data attribute contains 4 attributes, [[[Configurable]], [[Enumerable]], [[writable]], [[Value]].
When you use Object.defineproperty to modify a property descriptor, if the property does not exist before it, except for the attribute value specified in the code, the other attribute value defaults to False, for example:
Let obj = {};obj.name = ' test '; Object.defineproperty (obj, ' age ', { writable:false}); O Bject.getownpropertydescriptor (obj, ' age ');//console output information is as follows: Note Four attribute values are falseobject {value:undefined, Writable:false, Enumerable:false, Configurable:false}
Accessor properties cannot be defined directly and must be defined using Object.defineproperty, which contains 4 attributes, [[configurable]], [[Enumerable]], [[Get]], [[Set]]. Examples are as follows:
//Common ways to use accessor properties: Setting the value of one property causes other properties to change
Let book = 2004 1};object.defineproperty (book, ' year ' function () { return this ._year}, set: function (newvalue { if (Newvalue>2004
this
. _year = NewValue; this . Edition + = Newvalue-2004; } }});
Although we can also modify this property directly through Book._year access, the underscore in front of _year is a common notation that represents a property that can only be accessed through an object method, noting that this is a convention rather than a limitation of the language itself.
JavaScript Advanced Programming Reading notes (1)