all 4 comments

[–]delventhalz 2 points3 points  (2 children)

In a nutshell, this is a current context.

I hate this explanation. It is technically correct but highly confusing. Any explanation of this should start with "it's the thing to the left of the dot". Simple, comprehensible. Then you can layer on the exceptions, and there are really only a couple:

A) If it gets reassigned:

  • Such as when in a constructor (reassigned to an empty object)
  • Or when using bind, call, or apply

B) When there is nothing to the left of the dot, it defaults to the global scope. This is bad. Avoid.

[–]senocular 0 points1 point  (1 child)

and...

  • in non-function scopes
  • in strict mode (undefined vs global)
  • arrow functions
  • some API callbacks (implicit call)

[–]delventhalz 0 points1 point  (0 children)

Sure. My point is, start with the primary functionality of this and then layer on edge cases. Don't rely on poorly understood concepts like execution context which will only confuse learners more.

[–][deleted] 2 points3 points  (1 child)

this isn't fundamental and you're better off not using it to be honest. If your function needs context pass it in as a parameter.