JS study notes - this points to

default binding

  1. In the global environment, this points to window
  2. When the function is called independently, this inside the function points to window
  3. When called independently by a nested function, this points to window
  4. In the IIFE self-executing function expression, this points to window
  5. This in the closure points to window

implicit binding

When a function is a method in an object, this points to the direct object of the method

implicit loss

  1. alias the function
  2. Pass function as parameter
  3. When the function is a built-in function
    settimeout(function(){
          
          
    	//this指向window
    },3000);
    
  4. indirect call

explicit binding

  • Object.call()
  • Object.apply()
  • Object.bind()

new binding

When using new to instantiate an object, the this of the object points to the current instance
and the constructor property of the object points to the constructor

strict mode

  1. The this inside the independently called function points to undefined

Guess you like

Origin blog.csdn.net/m0_52761633/article/details/119767631