Skip to content

Instantly share code, notes, and snippets.

@robwhitaker
Created August 11, 2015 23:09
Show Gist options
  • Save robwhitaker/513bf821cc012d70588f to your computer and use it in GitHub Desktop.
Save robwhitaker/513bf821cc012d70588f to your computer and use it in GitHub Desktop.
Just a simple utility class for some callback handling.
function ReadyListener(config) {
this.properties = config || {};
this.onReady = function() {};
}
ReadyListener.prototype.ready = function(key) {
this.properties[key] === false && (this.properties[key] = true);
var isReady = true;
for(k in this.properties) isReady = isReady && this.properties[k];
isReady && this.onReady();
}
ReadyListener.prototype.then = function(callback) {
this.onReady = callback;
return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment