I'm trying to write a timer in javascript for a little game using classes. For some reason function start() doesn't work and it's execution turns timer's values (s and cs) into NaN. Is there something wrong with this keyword?
class Timer
{
constructor()
{
this.s = 0;
this.cs = 0;
}
start()
{
this.timerID = setInterval(function()
{
this.cs++;
if (this.cs >= 100)
{
this.s++;
this.cs = this.cs % 100;
}},
10);
}
stop()
{
clearInterval(this.timerID);
}
}
Thanks in advance.