Creo que quería explicar la diferencia entre arrow functions y normal functions pero acabé explicando this y closures por accidente

Glossary

What’s this article about?

Well... it’s not about execution contexts. It’s more about what execution contexts are not. It assumes you already know... wait, am I not just writing the same as in the previous article? I guess I just don’t know what this article is about. But it aims to go a bit deeper into the this binding in arrow functions and explores executions context as an inevitable side-effect. Also, worth mentioning it’s going to go as deep as my current knowledge allows me to... shit, I did it again.

Once I’ve finished writing it, I think I’ve kinda explained something about the difference between arrow and normal functions, this and closures.

The misconception

<aside> ❓ Arrow functions don't define their own this. In arrow functions, this refers to the same value as this in their outer lexical scope.

</aside>

I don't know who first described it that way, but everyone repeats it and it has always bugged me. Not because it's necessarily wrong but because, to me, it's a bad explanation.

First of all, I feel like everyone repeats it but doesn’t understand its meaning.

Second, it kinda makes it feel as if the value of this in an arrow function could be (or even was!) determined at compile-time.

Yes, in arrow functions, this refers to the same value as this in their outer lexical scope. But I have two issues:

I’d like I could rephrase it as:

<aside> ✅ Arrow functions don't bind a value to this. In arrow functions, the value of this is resolved through a lexical lookup, as if it was a lexical binding. But beware, the whole lookup might not be lexical.

</aside>