I am aware of the fact in the global context this
refers to the window
object meaning
function outer() {
console.log(this === window);
}
window.outer(); // true;
outer(); // true
Since, the function outer becomes a property of the window object.
But, when it is in the form of an inner function such as this :
const obj = {
method: function() {
function inner() {
console.log(this === window);
}
window.inner(); // TypeError: window.inner is not a function
inner(); // true
}
};
obj.method();
Going by the fact that it depends on the execution context to figure out this
when calling a function. So, if this === window
in this case which it is, shouldn't window.inner()
work too? I am a bit confused here ...