JS different ways to call a function in the Advanced --- this point, function

The function of this point

 

  • Who ordinary function of this Shi? ----- window
  • Object. Who is this approach that? ---- the current instance of the object
  • Who timer method of this Shi? ---- window
  • Who is this constructor that? ----- instance of an object
  • Who prototype object of this method in that? --- instance of an object

 

    // strict mode: 
    "use strict"; // strict mode 
    function F1 () { 
      the console.log ( the this ); // window 
    } 
    F1 ()

 

 

Different function is called

 

    // ordinary function 
    function F1 () { 
      the console.log ( "text can pick up a pen control LORI" ); 
    } 
    F1 (); 

    // constructor --- invoked by new, create object 
    function Fl () { 
      Console. log ( "I is the constructor, I am proud" ); 
    } 
    var F = new new Fl (); 

    // method object 
    function the Person () {
       the this .play = function () { 
        the console.log ( "play Code" ); 
      }; 
    } 
    var per = new new the Person (); 
    per.play ();

 

 

Guess you like

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