08 (h5 *) js Day 9

table of Contents:

 

1: prototype and prototype chain

    < Script > 
        @ . 1: using the object ----> using the object properties and methods, it is necessary to have a constructor 

        @ 1.1: Constructor. 
        function the Person (name, Age) {
             the this .name = name;
             the this .age = Age;
             the this .sayHi =  function () {   
                the console.log ( " Hello, you are so cool " ); 
            }; 
        }     
        
        // 1.2: Examples object, and initializes 
        var per =  new new the Person ( " Bob " , 20 ); 

        //1.3: If you want to use the properties and methods, and the value of each attribute in the object are the same, each object in the operation method is the same, then, in order to share data, save memory space, is the properties and methods by assigning prototype method 
        
        Person.prototype.sex =  " M " ; 
        Person.prototype.sayHello =  function () { 
            the console.log ( " how can you die handsome " ); 
        }; 

        console.dir (per );      // instance object 
        console.dir (the Person);   // constructor 

        // instance __proto__ prototype object constructor prototype and prototype is the same point, the prototype object points 
        // prototype object instance __proto__ prototype points to the constructor prototype prototype, the prototype object 

        // prototype object constructor is the constructor points where the prototype object 
        // instance object and the prototype object to contact by the prototype

        // example __proto__ prototype object's browser is used, not the regular 
        // constructor prototype is a prototype, is a programmer 

        @ prototype chain: is a relationship, the prototype object, and the object instance the relationship between, to contact relationship by prototype (the __proto__) 
        the console.log (per .__ proto__ == Person.prototype);
     </ Script >

 

Guess you like

Origin www.cnblogs.com/zyzmlc/p/11588263.html