Here is a fiddle.
I'm trying to create a countdown object that uses moment.js (a plugin that I prefer over using Date())
var Countdown = function(endDate) {
this.endMoment = moment(endDate);
this.updateCountdown = function() {
var currentMoment, thisDiff;
currentMoment = moment();
thisDiff = (this.endMoment).diff(currentMoment, "seconds");
if (thisDiff > 0)
console.log(thisDiff);
else {
clearInterval(this.interval);
console.log("over");
}
}
this.interval = setInterval(this.updateCountdown(), 1000);
}
I then create a instance of the countdown like so:
var countdown = new Countdown("January 1, 2014 00:00:00");
However the function only seems to run one time. Any ideas? Should I be using setTimeout() instead?