javascript setTimeout() first argument: expression error

Posted by Jonah on Stack Overflow See other posts from Stack Overflow or by Jonah
Published on 2010-04-09T01:45:06Z Indexed on 2010/04/09 1:53 UTC
Read the original article Hit count: 403

Filed under:
|
|
function Timer() {
 this.initialTime = 0;
 this.timeStart = null;

 this.getTotalTime = function() {
  timeEnd = new Date();
  diff = timeEnd.getTime() - this.timeStart.getTime();

  return diff+this.initialTime;
 };

 this.formatTime = function() {
  interval = new Date(this.getTotalTime());

  return  interval.getHours() + ":" +  interval.getMinutes() + ":" + interval.getSeconds();
 };

 this.start = function() {
  this.timeStart = new Date();

  setTimeout("this.updateTime()", 1000);
 };

 this.updateTime = function() {
  alert(this.formatTime());
  setTimeout("this.updateTime()", 1000);
 };
}


timer = new Timer();
timer.start();

I am getting an error:

this.updateTime is not a function

Any ideas?

Thanks

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about time