Skip to content

Instantly share code, notes, and snippets.

@mrgenixus
Created December 4, 2012 20:22
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 mrgenixus/4208288 to your computer and use it in GitHub Desktop.
Save mrgenixus/4208288 to your computer and use it in GitHub Desktop.
Used to provide a failover value from a deeply-nested object
var ValueStore = (function(){
var object_details = {};
var actual = function(input){
object_details = input || {};
}
actual.get = function(index,owner){
if(index.split('.').length > 1) return arguments.callee(index.split('.').slice(1).join('.'),(owner || object_details)[index.split('.').shift()]) || '';
return (owner || object_details)[index] || '';
}
return actual;
})();
//usage example:
v = new ValueStore({hello:{subject:{name:"World"}}});
v.get('hello.subject.name');
v.get('goodbye'); //= ''
v.get('goodbye.subject'); //= ''
v.get('goodbye.subject.name'); //= ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment