January 2020
Intermediate to advanced
548 pages
13h 36m
English
The this keyword is usually determined at the calltime of the function and will normally resolve to the object that the function is being invoked on. It is sometimes referred to as the execution context of a function or its thisArg. This can be unintuitive since it means that the this value can technically change between calls. For example, we could assign a method from one object to another, call it on the second, and observe that its this is always the object it's been called on:
const london = { name: 'London' };const tokyo = { name: 'Tokyo' };function sayMyName() { console.log(`My name is ${this.name}`);}sayMyName(); // => Logs: "My name is undefined"london.sayMyName = sayMyName;london.sayMyName(); // => Logs "My name ...Read now
Unlock full access