The relationship between JS and senior --- instance object constructor

Examples of relationships between objects and constructors:

  1. Examples of objects are created to process --- created by the constructor is called instantiation
  2. How to determine the object is not the type of data?
   1) instance of an object by way of the constructor. Constructor name == Constructor
   2) the name of the object constructor instanceof
   Use as a second way to identify, and why? Prototype start talking

 

 

    // object-oriented thinking is a process of abstraction ---- ----> instantiation process 

    // Sue the person, name, age, sex, eating, greeting, sleep 

    // custom constructor --- -> instantiate the object 
    function the Person (name, Age, Sex) {
       the this .name = name;
       the this .age = Age;
       the this .sex = Sex;
       the this .eat = function () { 
        the console.log ( "garlic mixed stinky durian sauce plus " ); 
      }; 
    } 
    // constructor ----> create objects 
    var per = new new the Person (" little Su ", 38," female " );
     // per.eat (); // eat 
    // instance object is created by the constructor 
    //Examples of objects pointing to own constructor (temporary understanding, is wrong) 
    // the structure of the object displayed 
    console.dir (per); 
    console.dir (the Person); 


    // constructor instances of an object (the constructor) 
    // constructor instance of an object is a Person, the result is true, so this is per instance of an object created by a Person to 
    console.log (per.constructor == Person); //
 
    console.log (per .__ proto__. constructor == the Person); 
    . the console.log (per .__ proto __ constructor == Person.prototype.constructor); 



    // constructor 
    function Animal (name) {
       the this .name = name; 
    } 
    // instance object 
    var Dog = new new Animal ( "rhubarb" );
    console.dir (Dog);// instance object 
    console.dir (Animal); // constructor name 

    the console.log (Dog .__ proto __ constructor. == the Person); 
    the console.log (Dog .__ proto __ constructor. == Animal); 


    // determine the object this data type is not 
    the console.log (dog.constructor == Animal); 
    the console.log (Dog the instanceof the Person);

Guess you like

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