-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.js
More file actions
44 lines (43 loc) · 975 Bytes
/
timer.js
File metadata and controls
44 lines (43 loc) · 975 Bytes
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
39
40
41
42
43
44
function Timer(fun, interval) {
this.fun = fun;
this.interval = !interval ? 1000 : interval;
}
Timer.prototype = {
fun: false,
stopped: true,
interval: 1000, // one second.
internaltimer: false,
setFunction: function(fun) {
this.fun = fun;
},
setInterval: function(a) {
this.interval = a;
},
start: function() {
if (this.stopped && this.fun) {
this.stopped = false;
this.internaltimer = setInterval(this.fun, this.interval, this);
}
},
end: function() {
if (!this.stopped) {
this.stopped = true;
clearInterval(this.internaltimer);
}
}
};
module.exports = Timer;
/*
main = function() {
var steps = 0;
var b = new Timer(function(timer) {
console.log("Ding:" + steps);
steps++;
if (steps > 25*10) {
timer.end();
}
},1000/25);
console.log("**");
b.start();
}
*/