this.setTimer = function(interval) { if (this.timer!= undefined) {clearInterval(this.timer)}; this.timer = setInterval(animate, interval); } this.setTimer(100);