Advertisement
Guest User

Untitled

a guest
May 5th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. function Timer(callback, delay) {
  2. var timerId, start, remaining = delay;
  3.  
  4. this.pause = function() {
  5. clearTimeout(timerId);
  6. remaining -= new Date() - start;
  7. };
  8.  
  9. this.resume = function() {
  10. start = new Date();
  11. clearTimeout(timerId);
  12. timerId = setTimeout(callback, remaining);
  13. };
  14.  
  15. this.getElapsedTime = function() {
  16. return new Date() - start;
  17. };
  18.  
  19. this.clear = function() {
  20. clearTimeout(timerId);
  21. };
  22.  
  23. this.resume();
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement