January 2019
Beginner
210 pages
4h 47m
English
In the global context, the this operator will always point to the global object. In a web browser, the window object is the global object:
console.log(this === window); // truethis.a = 37;console.log(window.a); // 37console.log(window.document === this.document); // trueconsole.log(this.document === document); // trueconsole.log(window.document === document); // true
The preceding example should be implemented using JavaScript. The preceding code will fail in TypeScript if the strict compilation flag is enabled because the strict flag enables the noImplicitThis flag, which prevents us from using the this operator in a scope in which its value is not clear, such as a global scope.
Read now
Unlock full access