Created
December 4, 2012 20:22
-
-
Save mrgenixus/4208288 to your computer and use it in GitHub Desktop.
Used to provide a failover value from a deeply-nested object
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
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