JavaScript prototype (prototype) and the prototype chain

①  __proto__ and constructor properties are  subject  unique.

prototype property is a function unique.

** JS function is in reference to the object type, so the function also has  __proto__  and  constructor  property

 

  __proto__ and prototype chain

(1) __ proto__ attributes are made an object point to an object, which points to their prototype object .

(2) __ proto__ attribute exists role: when accessing an object attribute A , if this is not the property within the object itself, will be traced back to the object (the __proto__ properties referred prototype object / objects parent ), if the parent objects the property itself does not exist, then traced back to the parent object is an object within the meaning of __proto__ property has been traced back to the prototype chain of top -null, and ultimately did not find the property a, returns undefined

(3) connected by a chain until __proto__ null attribute object that is the prototype chain

 

  prototype

 (1) prototype attributes are made to an object a function A , i.e. function A prototype object (the parent object), the object is also created a prototype of the function A (instantiate) an object prototype object

    (  New Funai ()) __ proto__ === funA.prototype

 (2) prototype effect of the presence attribute: This attribute can contain all the instance object properties and methods of sharing. (Instance object here is what should function instantiated)

 

   constructor

 (2) constructor properties are made: an object pointer to a function. The pointing function constructor. Each object has a constructor, Function is the constructor function itself. All functions and objects are ultimately come from the Function constructor, so the end of the constructor property is Function this function.

 

  inherit

  Inheritance refers to a direct use of the object properties and methods of another object.

 

 

Reference connection: https://chen-cong.blog.csdn.net/article/details/81211729

 

Guess you like

Origin www.cnblogs.com/winyh/p/11130304.html
Recommended