Skip to content

Instantly share code, notes, and snippets.

@iaingray
Created August 18, 2014 22:47
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 iaingray/33661b13e4f92737be5d to your computer and use it in GitHub Desktop.
Save iaingray/33661b13e4f92737be5d to your computer and use it in GitHub Desktop.
extendObject
/**
* Extends an object with addtional namespace nodes e.g. animals.birds.ducks.mallard
* @param base {Object} base object to be extended
* @param nodes {array} nodes to add
*/
extendObject : function(base, nodes){
if(typeof base !== 'object' || !(nodes instanceof Array)){
throw new Error ('Incorrect parameters passed to extendObject');
}
for( var i = 0; i < nodes.length; i++ ) {
base = base[ nodes[i] ] = base[ nodes[i] ] || {};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment