January 2019
Beginner
210 pages
4h 47m
English
The value of this inside a function depends on how the function is invoked. If we invoke a function in non-strict mode, the value of this within the function will point to the global object:
function f1() { return this;}f1() === window; // true
The preceding example should be implemented using JavaScript. The preceding code will fail in TypeScript when the strict compilation flag is enabled because it also enables the noImplicitThis flag.
However, if we invoke a function in strict mode, the value of this within the function's body will be undefined:
console.log(this); // global (window)function f2() { "use strict"; return this; // undefined}console.log(f2()); // undefinedconsole.log(this); // window ...Read now
Unlock full access