this Keyword in Different Contexts
Why will this code fail?
class Example {
constructor() {
setTimeout(function() {
this.method();
}, 1000);
}
method() {
console.log('Method called');
}
}
class Example {
constructor() {
setTimeout(function() {
this.method();
}, 1000);
}
method() {
console.log('Method called');
}
}