Is this a simple rule to remember what a this
is inside of an arrow function?
var that = this;
setTimeout((a, b) => { ... }, 1000); // the arrow function (a, b) => { ... }
and inside of that arrow function, all the this
can be just viewed as the same as that
.
Is this a simple rule to remember how it works?
Of course, if there is any regular ES5 function inside of the arrow function, then the this
inside of that ES5 function is different from that
, but will follow the old ES5 way.
Update: actually, later on, I found that one better way to think about it might be, just think of the arrow function the same as:
(function() { ... }).bind(this)
that is, the function taking away the this
as it currently is, the "lexical this".