Skip to content

Instantly share code, notes, and snippets.

@branneman
Created November 6, 2014 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save branneman/b1a846686587b7be588d to your computer and use it in GitHub Desktop.
Save branneman/b1a846686587b7be588d to your computer and use it in GitHub Desktop.
AMD Registry Pattern implementation
/**
* @module Registry pattern implementation
*/
define(function() {
'use strict';
/**
* Constructor
*/
function Registry() {
this._store = {};
}
/**
* Get value from store by key
* @param {string} key
*/
Registry.prototype.get = function get(key) {
return this._store[key];
};
/**
* Add key to store
* @param {string} key
* @param val
*/
Registry.prototype.set = function set(key, val) {
return this._store[key] = val;
};
/**
* Remove key from store
* @param {string} key
*/
Registry.prototype.remove = function remove(key) {
return delete this._store[key];
};
// Return Singleton
return new Registry;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment