Skip to content

Instantly share code, notes, and snippets.

@sandbochs
Created September 16, 2013 07:49
Show Gist options
  • Save sandbochs/6577728 to your computer and use it in GitHub Desktop.
Save sandbochs/6577728 to your computer and use it in GitHub Desktop.
function namespace(root, path, value){
path.split('.').reduce(function(object, key, i, namespace) {
if(i < namespace.length) {
return object[key] = (object.hasOwnProperty(key) ? object[key] : {})
}
return object[key] = (!value ? object[key] : value)
}, root)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment