Created
July 31, 2012 08:43
-
-
Save jiggliemon/3215076 to your computer and use it in GitHub Desktop.
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
/*global define:false, require:false */ | |
define(['./extend'], function (extend) { | |
'use strict'; | |
var _spaces = {}; | |
function namespace ( str ) { | |
var args = Array.prototype.slice.call(arguments,1) | |
,i = 0 | |
,base = window | |
,shards,length; | |
if (!str) { | |
return; | |
} | |
if (str.indexOf("::") >= 0) { | |
shards = str.split("::"); | |
base = window[shards[0]] = window[shards[0]] || {}; | |
str = shards[1]; | |
} | |
str = str.split('.'); | |
length = str.length; | |
for (i=0;i<length;i++) { | |
base = base[str[i]] = base[str[i]] || {}; | |
} | |
if (arguments.length > 1 && Object.extend) { | |
base = extend.call(base, args); | |
} | |
return base; | |
}; | |
// todo: Utilize the define property of namespace to cache/reference | |
// namespaces. This is for future use | |
// method: define || alias? | |
// | |
// namespace.define = function(str,obj){ | |
// spaces[str] = obj; | |
// }; | |
return namespace; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment