Lost this Binding in Timer Callback
A regular function passed to setInterval loses its this binding inside an object method.
Codejavascript
const timer = {
seconds: 0,
start() {
setInterval(function () {
this.seconds++;
console.log(this.seconds);
}, 1000);
}
};
timer.start();What is the bug in this code, and how do you fix it?