I have the following code:
/* MY CLASS */
class Cronometer{
constructor(){
}
getKey(key){
return JSON.parse(localStorage.getItem('taskRunning'))[key];
}
initCronometer(currentTask){
var startDate = new Date().getTime();
var config = {
"startDate": startDate,
"currentTask": currentTask
};
localStorage.setItem('taskRunning', JSON.stringify(config));
var idInterval = setInterval(function(){
var time = this.convertToTime( new Date().getTime() - this.getKey('startDate') );
console.log(time);
}, 1000);
return idInterval;
}
}
/* RUN */
var c = new Cronometer();
c.initCronometer(5555);
when I run the c.initCronometer(5555), I receive this message:
Uncaught TypeError: this.getKey is not a function
Somebody can tell me why that error is showing?