Skip to content

Instantly share code, notes, and snippets.

@lpirola
Created March 11, 2013 18:49
Show Gist options
  • Save lpirola/5136593 to your computer and use it in GitHub Desktop.
Save lpirola/5136593 to your computer and use it in GitHub Desktop.
Example Pattern Registry
function Registry(){
if(!this.instance){
/* object not yet created */
function registry(){ }
/* bunch of hashes for the passed object */
registry.prototype.reg = {}
/* method to add objects */
registry.prototype.add = function(name, object){
this.reg[name] = object;
}
/* method to obtain an object */
registry.prototype.get = function (name){
return this.reg[name];
}
this.instance = new registry();
}
return this.instance;
}
Registry().add('test', 3);
alert(Registry().get('test'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment