Created
November 9, 2009 10:15
-
-
Save ThisIsMissEm/229854 to your computer and use it in GitHub Desktop.
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
jet.namespace = function(/*String*/ namespace, /*Object?*/ properties){ | |
// 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: | |
// | jet.namespace("a.b.c"); | |
// | #=> a = {}; a.b={}; a.b.c={}; | |
// example: | |
// | jet.namespace("a.b").c = function(){}; | |
// example: | |
// | jet.namespace("a.b.c", function(){}); | |
var current = jet.global; | |
for(var node, parts = namespace.split('.'); parts.length && (node = parts.shift());){ | |
if(properties && parts.length == 0){ | |
if(Object.prototype.toString.call(properties) === '[object Function]'){ | |
current = (current[node] = properties); | |
} else { | |
current = (current[node] = jet.mixin(current[node], properties) || {}); | |
} | |
} else { | |
current = (current[node] = (current[node] === undefined) ? {} : current[node]); | |
} | |
} | |
return current; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment