In the lower example, why does the function outer
which is assigned as method to the object-property with the identifier meth
does not have an execution context which would be the this
in the inner
-function?
Since the function outer
assigned to meth
seems to automatically get the this
-keyword set to the surrounding object as execution context, you could assume, that the function inner
is getting handled the same way, or is it because a surrounding function can not be seen as an execution context, therefore JavaScript does not know for the function inner
which execution context it is in, so it assumes the default, which is then window
?
var foo = {
meth: function outer() {
console.log(this);
// let that = this;
function inner() {
console.log(this);
}
inner();
}
};
//Output
{meth: ƒ}
Window {parent: Window, opener: null, top: Window, length: 0, frames: Window, …}
Thanks in advance for demystifying