Front-end study notes (20) of the arrow function in JS points to the problem

Let me talk about the this point of the ordinary function. To judge the this point of the ordinary function, you don't need to consider the definition environment of the function. You only need to consider the function call. Whoever calls the function is the this of the function.

Regarding the arrow function in ES6, the official explanation is:
the this in the arrow function is the context, and the this in the outer scope is the this in the arrow function.

Judging the this of the arrow function:
Tip : It has no function in the outer layer, and this is the window.
There are functions in the outer layer. See who the this of the outer function is, and whose this is.

(The outer function may be a regular function or an arrow function. Different methods are used to determine the outer this according to the type of function. If the outer function is a regular function, it depends on who called the outer function. The outer function is an arrow function. To judge by the techniques just mentioned)

To give a small example:
Insert picture description here
this printed here is window. It can be judged according to the rules just mentioned.

Finally, one more detail:
the this method in the
arrow function
cannot be changed , because the arrow function does not have this, and call / apply / bind cannot change the this point of the arrow function.

Guess you like

Origin blog.csdn.net/qq_42698576/article/details/108110217