In JavaScript, the pointing types of this are: 1. Global object; 2. Function call; 3. Constructor call; 4. Event handler; 5. Arrow function (inheriting outer this). Additionally, you can explicitly set what this points to using the bind(), call(), and apply() methods.
The pointer of this in JavaScript
The type pointed by this
JavaScript, this points to the following types:
1. Global object
2. Function call
const person = { name: "John", greet: function() { console.log(this.name); }}; person.greet();
3. Constructor call
const person = new Person("John");
##4. Event handler
5. Arrow function
Notes
The above is the detailed content of There are several situations where this in js points to. For more information, please follow other related articles on the PHP Chinese website!