title: How to access global variable after setInterval function. variables gives undefined or NaN even after it is set
body: <p>This is a typescript class. I am trying to access the starttime &amp; 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?</p>
  
  <pre><code>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);
   }
  </code></pre>