The arrow function is of the form () => XXX. It is written as a single line, leaving out the parentheses, return and semicolon after the statement. The arrow function is used because it is cleaner than normal and does not bind this. So what is this of the arrow function? The first is to write a setTimeout code directly
So the output is going to be direct
So let’s switch to objects
That is, you put these two in the method of the object, the output of the arrow function is the object, and the output of the normal function is the window.
Why is that?
This of the arrow function refers to this in the most recent scope.
SetTimeout (function{},500) This is bound by call, and the window is passed in first.
SetTimeout (() => {},500) this is the scope of aaa. Aaa is defined in an object, so this is the current object. Let’s take a look at this
The first one is in a normal function, so it’s window
Function (){}; function(){};
The third, of course, is Window.
And the fourth one is the arrow function that goes out, and the arrow function that goes out is aaa’s scope, so the call to the function inside the object, that’s the object.