Created
April 17, 2013 12:53
-
-
Save vaibhavguptaIITD/5404009 to your computer and use it in GitHub Desktop.
javascript: initialize an object with nested properties
This file contains hidden or 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 app = {} | |
app.ensure_struct = function(atts,scope){ | |
var scope = scope || this; | |
if (atts == "") { | |
return scope; | |
} | |
var parts = atts.split('.'), | |
first_attribute = parts.shift(); | |
if (typeof (scope[first_attribute]) === 'undefined') { | |
scope[first_attribute] = {}; | |
} | |
app.ensure_struct(parts.join('.'), scope[first_attribute]); | |
return scope; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment