this point summary

    // this point in time is to determine the function definition can not, only when the function is performed in order to determine this point in the end who is, in fact, this final point is that calling it an object.
     // Depending on how different function calls, this will point to different objects, there is no way to create a relationship with. 


    // 1, when invoked as a function of. this points to the window 
    function Fun () { 
        the console.log ( this .name) 
    } 
    // Fun (); 



    // that object 2, when calling the form of a method, this method is invoked 
    var obj = { 
        name: " Bob " , 
        AA: Fun 
    }; 

     // obj.aa (); 



    // . 3, if the call is not the first layer, then this will point to the current layer 
    var A = { 
        B: . 5 , 
        C: { 
            B:10 , 
            D: function () { 
                the console.log ( the this .B) 
            } 
        } 
    }; 

    // ACD () 



    // . 4, if this method is assigned to the variable, this will change the pointing object 

    var n-= { 
        name: " Gouzi " , 
        FirstName: function () { 
           the console.log ( the this .name) 
        } 
    }; 

    var X = { 
        name: " fool " 
    }; 

    x.firstname = n.firstname;
     // x.firstname ()
    n.firstname () 



    // . 5, in the constructor, this point instantiated object 


    var Person = function () {
         the this .name = " Cai Xu Kun " 
    }; 

    var CXK = new new Person ();
     // the console.log (cxk.name)

 

Guess you like

Origin www.cnblogs.com/dumenglong/p/11037767.html