I have learned something, I have learned that JS (and conversely in some cases TS) is a bitch when it comes to scoping (and, conversely, why we had `self` throughout a code-base).
So, basically, if a function definition is thus:
const obj = {
sayHello: function () {
console.log(this);
}
}
obj.sayHello() // prints: [Function:print]
the scoping means that `this` points to the function definition, so in order to reference obj within that function, you need an alias (i.e. `self=this`).
When we use the following, however:
const obj = {
sayHello: () => {
console.log(this);
}
}
obj.sayHello() // prints: Window
We get the original object (in this case it’s the global object, Window)
So… today, I’ve learned that it’s a pain in my arse, and I have some code to revert!
