Chapter VI Object Oriented Programming

  1. Understood objects: . A data attribute: [[the Configurable]] Boolean value that indicates whether to delete properties, [[Enumerable]] indicates whether the for-in cycle property, [[the Writable]] possible change value of the property, [[the Value ]] value contains attribute data attributes methods Objec.defineProperty ( 'Object' , 'attribute', { properties: to true, attribute: value }); b. access properties: in addition Configurable and Enumerable addition to properties, but also there Get and Set attribute of the call attributes are read and write property functions, Object.definePropertie ( 'objects', { attribute: {} , the attribute {}}) method can be defined one time a plurality of attributes; C. read take characteristic property: If you want to read the property set through the property of those descriptors, byObject.getOwnPropertyDescriptor ( object properties of the object );
  2. Create Object: ① use new to create objects operator automatically creates a new assignment within the scope of the object and to the object constructor, the execution code, and returns the object ; ② objects .call ( Examples ) show that created in Example after the constructor of the object instance you can obtain all the properties and methods of the object; ③ each function has prototype prototype property, which is a pointer to an object that contains all the shared attributes and examples method; each new instance ④ there is a pointer pointing to the prototype object constructor, the pointer in the example of prototype attributes the __proto__; therefore on the properties and methods of the prototype object constructor function can be shared by all instances, and properties and methods are the constructor is private, to judge whether there is such a relationship between an instance and a prototype object constructor may call the constructor .prototype.isPrototypeOf ( example ) method for determining; when the access attribute will first search in the example, the search will not search in the prototype object; the Examples of use (.hasOwnProperty property ) returns only when a given object instance attribute exists in only to true ; used in operator possible to determine a property of the instance is present or whether the object instance attribute in  Example, if there returns true, the use forin the cycle traversal attribute, the object will return all the properties of the prototype object or in terms of examples; ⑤ when rewriting the prototype object constructor, to the prototype object constructor properties pointing constructor
  3. Inheritance: Principle: Let the constructor prototype object itself points to another instance of the prototype object or prototype object of another, when using the literal rewrite the prototype of the constructor, if the constructor inherits another constructor's prototype object , you need to add the literal constructor : another constructor .prototype, now usually by a call to modify the scope inherit attributes and can also achieve transmission parameters, using the modified prototype object constructor function points to an instance of another constructor method to inherit (with the necessary modifications to constructor points to itself constructor) properties and methods of the prototype object, the parent constructor remember, after being inherited properties and methods will become sub-constructor

Guess you like

Origin www.cnblogs.com/Liqian-Front-End-Engineer/p/11258768.html