This article mainly describes the arrow function in the context of ES6 this pointing problem

Arrow functions have no this pointer in scope. If we use this inside the arrow function, this continues to point to this outside the execution context of the arrow function.

Here’s a quick example:

Var obj = {console.log(this.hobby)}} obj. Func ()=>{console.log(this.hobby)}} obj. Var obj1 = {hobby:" learn ", Func :function(){var func1 = ()=>{console.log(this.hobby)} return func1()// This step defaults to calling external func and performing the call}} Obj1.func () // Called in object mode, func1's execution context is func, that is, func1's external execution context is func, this points to func, and also points to obj1 // output learning at the same level as funcCopy the code

1. In an object method, if the type of the method is an arrow function, the this pointer in the arrow function does not point to the object itself, but to the outer window.

2. If the arrow function is nested within an ordinary function that exists on an object and is called as an object method, the this pointer inside the arrow function points to that object.