Skip to content

Instantly share code, notes, and snippets.

@ThisIsMissEm
Created January 13, 2010 13:48
Show Gist options
  • Save ThisIsMissEm/276194 to your computer and use it in GitHub Desktop.
Save ThisIsMissEm/276194 to your computer and use it in GitHub Desktop.
function set(/*String*/ namespace, /*Object?*/ properties, /*Mixed*/ value){
// summary:
// Creates & Resolves an objects structure based on the given Namespace string.
// namespace:
// A string representing an object tree, each level separated by a period.
// example:
// | namespace("a.b.c");
// | #=> a = {}; a.b={}; a.b.c={};
// example:
// | namespace("a.b.c", function(){});
// | #=> a = {}; a.b={}; a.b.c=function(){};
for(var node, parts = namespace.split('.'); parts.length && (node = parts.shift());){
current = (current[node] = (current[node] === undefined) ? {} : current[node]);
}
return current = (current = value);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment