The early programmer struggles with the Javascript keyword this
. But understanding your this
context is easier than it seems.
This
is all about where a function is invoked.
Often, early programmers worry about where the function was declared. Perhaps the function was declared in a specific file or a particular object. Surely this changes it's this
!
Nope.
To understand this
, we need to see where it is invoked. Nothing else matters, with one exception which we'll cover in a moment.