Created
December 6, 2011 23:09
Revisions
-
matthanger created this gist
Dec 6, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ /** * Registers the specified namespace, ensuring all parts of the namespace are created. If the namespace * already exists, it will not be modified. * * Usage: * namespace('foo.bar'); * foo.bar.baz = 'qux'; * * @param {String} namespace The namespace to register. Namespaces are hierarchal, and are separated by dots. */ window.namespace = function(namespace) { var parts = namespace.split("."); var root = window; for(var i=0; i<parts.length; i++) { root = root[parts[i]] = root[parts[i]] || {}; } };