forked from Eluch/Soccribe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnamed_functions.js
38 lines (30 loc) · 972 Bytes
/
named_functions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var timeoutNames = {};
var intervalNames = {};
module.exports = {
clearNamedTimeout: function (name) {
if (timeoutNames[name] === undefined) {
timeoutNames[name] = null;
}
if (timeoutNames[name] !== null) {
clearTimeout(timeoutNames[name]);
timeoutNames[name] = null;
}
},
setNamedTimeout: function (name, callback, delay) {
this.clearNamedTimeout(name);
timeoutNames[name] = setTimeout(callback, delay);
},
clearNamedInterval: function (name) {
if (intervalNames[name] === undefined) {
intervalNames[name] = null;
}
if (intervalNames[name] !== null) {
clearInterval(intervalNames[name]);
intervalNames[name] = null;
}
},
setNamedInterval: function (name, callback, delay) {
this.clearNamedInterval(name);
intervalNames[name] = setInterval(callback, delay);
},
};