Created
March 11, 2013 18:49
-
-
Save lpirola/5136593 to your computer and use it in GitHub Desktop.
Example Pattern Registry
This file contains 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 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