// object
let user = {
name: "Joe",
sayHi() {
console.log(`Hi, I am ${this.name}.`);
// ╰──╯
// ↳ ⭐️ value of `this` is NOT determined here.
console.log(`... (sayHi() called by ${this})`)
}
};
// ❗assign a new name
let f = user.sayHi; // ⭐️ the function is NOT invoked here❗
// ⭐️ call site #1
user.sayHi(); // ⭐️ this === user (object before "dot")
// Hi, I am Joe.
// ... (sayHi() called by [object Object])
// ⭐️ call site #2
f(); // ❗this = window / globalObject / undefined❗
// ❗this.name = undefined / undefined / ⛔ TypeError❗
// ❗Hi, I am undefined.
// ❗... (sayHi() called by [object global])