case One: The parameter passed in is the alias of the function, then this is to point to window ;
Scenario Two: The incoming parameter is the new over the constructor, then this is to point to the instantiated object itself;
Scenario Three: If we want to put an incoming function object inside this pointer to the object defined by the external literal, then we are using the Apply and Call
We can see my conclusion in code as follows:
<script type= "Text/javascript" >varName = "I am Window";varobj ={name:"Sharpxiajun", Job:"Software", Ftn01:function(obj) {obj.show (); }, Ftn02:function(FTN) {ftn (); }, Ftn03:function(FTN) {Ftn.call ( This);//call and apply is to point the this pointer to the first parameter of the method }};functionPerson (name) { This. Name =name; This. Show =function() {Console.log ("Name:" + This. Name); Console.log ( This); }}varp =NewPerson (' person '); Obj.ftn01 (P); Obj.ftn02 (function() {Console.log ( This. Name); Console.log ( This; }); o Bj.ftn03 (function() {Console.log ( This. Name); Console.log ( This);});</script>
The results are as follows:
Finally, let's summarize:
if the JavaScript The language didn't pass new. (including object literal definition), call and Apply change the This of the function pointer, function of this The pointers are all pointing to the window the .
The this pointer in the "Go" javascript