Last active
December 23, 2015 08:09
-
-
Save gaina-jp/6605315 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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