consider the following snippet of code:
function Animal() {
}
Animal.prototype.run = function() {
(function() {
console.log(this);
})();
}
var g = new Animal();
g.run();
It logs Window
and this makes sense, but in the following piece, it outputs undefined
!!!:
class Animal {
run() {
(function() {
console.log(this);
})();
}
}
var g = new Animal();
g.run();
This is the same code but using class syntax, what is different in class syntax that made this
equal undefined
?