中央定時器控制
阿新 • • 發佈:2017-11-21
ext cti spl timeout top next() -- bsp nbsp
var timer = { timerId : 0, timers : [], add : function(fn){ this.timers.push(fn); }, start : function(){ if(this.timerId){ return; } (function runNext(){ if(timer.timers.length > 0){for(var i = 0; i < timer.timers.length; i++){ if(timer.timers[i]() === false){ timer.timers.splice(i,1); i--; } } timer.timerId = setTimeout(runNext,0); } })(); }, stop :function(){ clearTimeout(this.timerId); this.timerId = 0; } };
中央定時器控制