Skip to content

Instantly share code, notes, and snippets.

@danscotton
Created June 1, 2012 16:00
Show Gist options
  • Save danscotton/2853184 to your computer and use it in GitHub Desktop.
Save danscotton/2853184 to your computer and use it in GitHub Desktop.
Config singleton
define(function() {
// Config object
var Config = function( initialSettings ) {
var store = (initialSettings && typeof initialSettings === 'object') ? initialSettings : {};
return {
get: function( key ) {
if(key) return store[key];
return store;
},
set: function( key, value ) {
store[key] = value;
},
has: function( key ) {
return store[key] ? true : false;
}
};
};
// save instance so any further calls to config()
// return the same instantiated config object.
var instance = null;
return function( initialSettings ) {
if(instance === null) instance = new Config( initialSettings );
return instance;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment