This is an attribute in the execution context that points to the object on which the method was last called. In real development, the direction of this can be determined by four invocation patterns.

  • The first is the function call pattern, where this refers to the global object when a function is called directly as a function that is not a property of an object.
  • The second is the method invocation pattern, where if a function is called as a method of an object, this refers to that object.
  • The third is the constructor invocation pattern. If a function is called with new, a new object is created before the function is executed. This refers to the newly created object.
  • The fourth is the apply, call, and bind call modes, all of which can display the this pointer to the specified calling function.

Of the four, the constructor invocation pattern has the highest priority, followed by apply, Call, and bind, followed by method invocation, and then function invocation.