JS study notes - this points to
default binding
- In the global environment, this points to window
- When the function is called independently, this inside the function points to window
- When called independently by a nested function, this points to window
- In the IIFE self-executing function expression, this points to window
- 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
- alias the function
- Pass function as parameter
- When the function is a built-in function
settimeout(function(){ //this指向window },3000);
- 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
- The this inside the independently called function points to undefined