6th Chapter
1.ES has two properties: Data properties and accessor properties. Attributes contain various attributes that represent the various characteristics of a property.
Data properties: [[[Configurable]],[[enumerable]],[[writable]],[[value]]
To modify a property using: Object.defineproperty ()
Accessor properties: [[[Configurable]],[[enumerable]],[[get]],[[set]]
Accessor properties do not contain numeric values. can only be defined by Object.defineproperty (). The behavior of reading and writing is set by setting the set and get functions, respectively. P141
2. Other ways to attribute attributes:
Object.defineproperties () setting multiple properties and their attributes
Object.getownpropertydescriptor () Properties of the Read property
3. Create the schema for the object:
4. Factory mode: resolves duplicate code issues but does not recognize object types
5. Constructor mode: The object type can be recognized, but each method is recreated on the instance. The same name function on different instances is unequal.
A function called by new is a constructor, and a direct call is a normal function.
6. Prototype mode: Instead of defining the information for an object instance in the constructor, add the information directly to the prototype object, and let all the object instances share the properties and methods it contains.
Prototype object: (1) When creating a new function, create the prototype property of the function and point to the prototype object of the function.
(2) The prototype object generates a constructor property that points to the function where the prototype is located.
(3) Call the constructor to create a new instance, containing a pointer [[prototype]] inside the instance, pointing to the prototype object
Method of Prototype object: Object.prototype.isPrototypeOf (instance), Object.getprototypeof (instance), instance. hasOwnProperty (attribute), Objet.key (instance or prototype), Object.getownpropertynames (instance or prototype)
If you override the prototype object after the call to the constructor to create an instance, the instance's [[prototype]] cannot point to the new prototype object. P156
Prototype mode disadvantage: All instances have the same attribute value, as a result of sharing, the modification of instance 1 will be reflected in instance 2
7. Combining constructor and prototype patterns: Define properties in constructors, prototype definition methods, and properties that need to be shared
8. Dynamic Prototyping Mode: When the method does not exist, it is in the prototype creation method
9. Parasitic constructor mode: Creates a new object in the constructor and returns the object.
The constructor returns a new object instance by default when it does not return a value. You can override the value returned by the calling constructor by adding a return at the end of the constructor.
10. Secure constructor Mode: Avoid using this and new, some property values can only be accessed through a unique method.
JS Elevation Note 6 Chapter