JS Advanced --- prototype point can be changed and the prototype chain

Prototype and prototype chain may be changed to point

Prototype __proto__ instance object points to a prototype object constructor of the object is located

Prototype object constructor (the prototype) If the change point, the prototype object instance (the __proto__) is also changed to point

Prototype point can be changed

The relationship between the object and the prototype object instance is to be linked by __proto__ prototype, this relationship is the prototype chain

 

Illustrated as follows

 

 

 

Observing console understand the code

    // al constructor 
    function the Person (Age) {
       the this .age = 10 ; 
    } 
    // archetypes object method 
    Person.prototype.eat = function () { 
      the console.log ( "people eat" ); 
    }; 
    / / student constructor 
    function student () { 

    } 
    Student.prototype.sayHi = function () { 
      the console.log ( "Hey, Sue Shuaio Hello" ); 
    }; 
    // prototype students, points to a person examples of objects 
    Student.prototype = new new the Person (10 );
     var STU = new new  Student ();
    stu.eat (); 
    stu.sayHi (); 

    // prototypes point can change 
    // instance object prototype __proto__ points is the constructor of the object is located prototype object 
    // prototype object constructor (the prototype) pointing If you change the prototype object instance (__proto__) points will change 

    // prototype point can be changed 
    // relationship between instances of objects and prototypes are objects to be linked by __proto__ prototype, this relationship is prototype chain

 

Guess you like

Origin www.cnblogs.com/jane-panyiyun/p/12152006.html