Created
June 1, 2012 16:00
-
-
Save danscotton/2853184 to your computer and use it in GitHub Desktop.
Config singleton
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
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