marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.01k stars 795 forks source link

Ch. 6, Methods, "this" binding for arrow functions #357

Closed dhollinden closed 6 years ago

dhollinden commented 6 years ago

In the following paragraph

"Arrow functions are different—they do not bind their own this, and thus you can do something like the following code, which references this from inside a local function."

For me, it would be helpful to state how "this" is actually bound, perhaps like the following:

Arrow functions are different—they do not bind their own this. Instead, this retains the value of the enclosing lexical context's this. You can, therefore, do something like the following code, which references the enclosing this from inside a local function.

I took the language "this retains the value of the enclosing lexical context's this" from MDN Web Docs.

Thank you

marijnh commented 6 years ago

Attached patch should help here.

dhollinden commented 6 years ago

Great. Thank you!