Given the following code, why doesn't (obj.foo)()
receive window
as this
? It seems to me like the parentheses are ignored, rather than treated as an expression that evaluates to foo
?
window.bar = 'window';
const obj = { bar: 'obj' };
obj.foo = function() {
console.log(`Called through ${this.bar}`);
}
obj.foo(); // Called through obj
(obj.foo)(); // Called through obj - Why?
(0, obj.foo)(); // Called through window
(true && obj.foo)(); // Called through window