-
-
Save Efreak/352856b7867a94d3b1ed 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
/** | |
* Original by Zirak @ http://stackoverflow.com/a/8636050/1012431 | |
* | |
* Had some issues with the clear function | |
* | |
* @type {{intervals: Array, make: make, clear: clear, clearAll: clearAll}} | |
*/ | |
var interval = { | |
//to keep a reference to all the intervals | |
intervals : [], | |
//create another interval | |
make : function (fun, delay) { | |
var newKey = this.intervals.length +1; | |
this.intervals[newKey] = setInterval(fun,delay); | |
return newKey; | |
}, | |
//clear a single interval | |
clear : function ( id ) { | |
clearInterval( this.intervals[id] ); | |
delete this.intervals[id]; | |
return true; | |
}, | |
//clear all intervals | |
clearAll : function () { | |
for (var key in this.intervals) { | |
clearInterval(this.intervals[key]); | |
delete this.intervals[key]; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment