I want to define a object that hold a interval that can be reset
var intervalHolder = {
make : function() {
this.clean();
this.interval = setInterval(function () {
console.log("make interval");
}, 3.0 * 1000);
},
clean: function(){
if(this.interval){
console.log("clean interval");
clearInterval(this.interval);
}
}
};
intervalHolder.make() was designed to clean old interval and make a new one
but I found that when invoke the intervalHolder.make() multiple times , there will be a time gap between log clean interval and make interval, not immediately as expected. is clearInterval()' too time consuming?