Last active
August 29, 2015 14:05
-
-
Save jackwanders/929656ed18c3fb0bf001 to your computer and use it in GitHub Desktop.
A proof of concept method for creating multiple levels of hierarchy within an object in one shot, regardless of whether they already exist
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
/** | |
* PropAddr | |
*/ | |
var PropAddr = function(obj) { | |
var props = [], | |
i; | |
if(arguments.length === 2) { | |
props = arguments[1].split('.'); | |
} else { | |
props = Array.prototype.slice.call(arguments, 1); | |
} | |
if(props.length < 1) { return; } | |
if(typeof obj[props[0]] === 'undefined') { | |
obj[props[0]] = {}; | |
} | |
PropAddr.apply(this, [obj[props[0]]].concat(props.slice(1))); | |
}; | |
// Examples | |
// PropAddr(window, 'propAddrObj.level1.level2.level3'); | |
// PropAddr(window, 'propAddrObj2', 'level4', 'level5', 'level6'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment