-
-
Save modulexcite/7d1fa279d5aa53cab82d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function Stopwatch() | |
{ | |
var sw = this; | |
var start = null; | |
var stop = null; | |
var isRunning = false; | |
sw.__defineGetter__("ElapsedMilliseconds", function() | |
{ | |
return (isRunning ? new Date() : stop) - start; | |
}); | |
sw.__defineGetter__("IsRunning", function() | |
{ | |
return isRunning; | |
}); | |
sw.Start = function() | |
{ | |
if(isRunning) | |
return; | |
start = new Date(); | |
stop = null; | |
isRunning = true; | |
} | |
sw.Stop = function() | |
{ | |
if(!isRunning) | |
return; | |
stop = new Date(); | |
isRunning = false; | |
} | |
sw.Reset = function() | |
{ | |
start = isRunning ? new Date() : null; | |
stop = null; | |
} | |
sw.Restart = function() | |
{ | |
isRunning = true; | |
sw.Reset(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment