Skip to content

Instantly share code, notes, and snippets.

@gaina-jp
Last active December 23, 2015 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaina-jp/6605315 to your computer and use it in GitHub Desktop.
Save gaina-jp/6605315 to your computer and use it in GitHub Desktop.
(function(g,u){
"use strict";
/**
* TimerManagement
*/
var TimerManagement = (function(){
/**
* TimerManagement
* @param {Number} interval
* @constructor
*/
function TimerManagement(interval){
this._timerObj = {};
this._defaultInterval = interval || 33;
}
var p = TimerManagement.prototype;
/**
* setTimer
* @param {String} name
* @param {Function} func
* @param {Number} interval
*/
p.setTimer = function(name,func,interval){
if(typeof name !== "string") throw new Error("need String");
if(typeof func !== "function") throw new Error("need Function");
if(typeof interval !== "number" && typeof interval !== u) throw new Error("need Number or dont use");
this._timerObj[name] = setInterval(func,interval || 33);
};
/**
* removeTimer
* @param {String} name
*/
p.removeTimer = function(name){
if(this._timerObj[name]){
clearInterval(this._timerObj[name]);
delete this._timerObj[name];
}else{
return null;
}
};
/**
* getTimers
* @returns {Object} _timerObj
*/
p.getTimers = function(){
return this._timerObj;
};
/**
* setDefaultInterval
* @param {Number} interval
*/
p.setDefaultInterval = function(interval){
this._defaultInterval = interval;
};
return TimerManagement;
})();
if(g.TimerManagement === u){
g.TimerManagement = TimerManagement;
}
}(this,void 0));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment