this can change
In methods, this means the object the method was called on. But pass that method somewhere else — as a callback, say — and this can go missing. Today you'll learn the rules and how to control them.
this depends on the call
const shop = {
name: "Momo House",
hello() {
return "Welcome to " + this?.name;
},
};
console.log(shop.hello());
const loose = shop.hello;
console.log(loose());Rule of thumb: look at what's left of the dot at the moment of the call. No dot, no this.