This is a typescript class. I am trying to access the starttime & count in setInterval function. I have set the values before,why do we get undefined and NaN in it? and how do I solve this issue?
startTimer() {
this.startTime = new Date();
this.count = 100;
console.log("STARTTIME: " + this.startTime); //RESULT: Mon Dec 17..etc
console.log("COUNT: " + this.count); //RESULT: 100
this.timer = setInterval(function () {
console.log("STARTTIME: " + this.startTime); //Undefined
this.count += 1;
console.log("COUNT: " + this.count); //NaN
}, 1000);
}