I am curios why this ES6 code outputs undefined
:
class Test {
constructor(name) {
this.name = name;
}
log() {
console.log(this);
}
}
const t = new Test('asd');
const asd = t.log;
asd();
but this ES5 code outputs window
.
function Test(name) {
this.name = name;
}
Test.prototype.log = function() {
console.log(this)
}
const t = new Test('newer test');
const asd = t.log;
asd();
Techincally with something is invoked in the globar score it has window.thatSomething in front but apparently if thatSomething is a class there is no window.