Trying to figure out how this references resolve to the lexical context when using arrow functions as callback functions. My suspicion is the this references in the body of the callback function are resolved before the method is invoked. I.e., before the arrow function is passed as an argument (rather than at each iteration for example if the method is forEach()). But I can't seem to find anything definitive on this. I did attempt to log the passed function but writing my own forEach() function thinking I could capture the difference between a passed arrow function and a passed non-arrow function. But the func parameter, converted to string for log purposes, revealed essentially nothing - show this still in the function (unresolved).
Asked
Active
Viewed 25 times
1 Answers
0
We can refer to the language specification that states that an arrow function gains knowledge of the value of this
during its instantiation: https://262.ecma-international.org/12.0/#sec-runtime-semantics-instantiatearrowfunctionexpression

a better oliver
- 26,330
- 2
- 58
- 66