this

Any access to this keyword within a function is actually controlled by how the function is actually called. It is commonly referred to as the “calling context.”

Here is an example:

  1. function foo() {
  2. console.log(this);
  3. }
  4. foo(); // logs out the global e.g. `window` in browsers
  5. let bar = {
  6. foo
  7. }
  8. bar.foo(); // Logs out `bar` as `foo` was called on `bar`

So be mindful of your usage of this. If you want to disconnect this in a class from the calling context use an arrow function, more on that later.