Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Created May 24, 2013 20:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwaldron/5646160 to your computer and use it in GitHub Desktop.
Save rwaldron/5646160 to your computer and use it in GitHub Desktop.
Something more scalable and organized then tacking junk onto the global object.
[[Global]].Timer = {};
Timer.Frame = function(handler) {
// ... does what rAF(handler) would do
};
Timer.Frame.prototype.cancel = function() {
// kills this Timer.Frame instance
};
Timer.Frame.prototype.pause = function() {
// prevents handler from being invoked in the
// next turn
};
Timer.Frame.prototype.resume = function() {
// if pause() was previously called,
// schedule the handler to be invoked
// in the next turn
};
Timer.Immediate = function(handler) {
// at the end of this turn invoke the handler
};
Timer.Timeout = function(ms, handler) {
// at the end of this turn,
// wait "ms" and invoke the handler
};
Timer.Timeout.prototype.cancel = function() {
// cancel the invocation of this Timer.Timeout
// instance's handler if it has not yet been
// invoked.
};
Timer.Interval = function(ms, handler) {
// at the end of this turn,
// wait "ms" and invoke the handler
};
Timer.Interval.prototype.cancel = function() {
// cancel the invocation of this Timer.Timeout
// instance's handler if it has not yet been
// invoked.
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment