I thought I understood the mechanism of this in JS but -> I can't explain why if you define and call a function in the method of a JS Class (syntax Class), this value of 'this' in this function is undefined when I expected it to be window.
Not included in the snipet but I tried to check if the context of the method was executed in strict mode and it was not.
I tried the code in js fiddle and on my chrome browser console.
class ComponentClass {
classMethod() {
function funcInMethod() {
console.log('this in in the function funcInMethod defined and called from the method class: ', this);
}
funcInMethod();
}
}
var classInstance = new ComponentClass();
classInstance.classMethod();
// logged: > undefined
// expected: > window