Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Timer(callback, delay) {
- var timerId, start, remaining = delay;
- this.pause = function() {
- clearTimeout(timerId);
- remaining -= new Date() - start;
- };
- this.resume = function() {
- start = new Date();
- clearTimeout(timerId);
- timerId = setTimeout(callback, remaining);
- };
- this.getElapsedTime = function() {
- return new Date() - start;
- };
- this.clear = function() {
- clearTimeout(timerId);
- };
- this.resume();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement