master
1/***
2 * @method namespace([init] = global)
3 * @author andrewplummer
4 * @returns Mixed
5 * @short Finds the namespace or property indicated by the string.
6 * @extra [init] can be passed to provide a starting context, otherwise the global context will be used. If any level returns a falsy value, that will be the final result.
7 * @dependencies ES5
8 * @example
9 *
10 * 'Path.To.Namespace'.namespace() -> Path.To.Namespace
11 * '$.fn'.namespace() -> $.fn
12 *
13 ***/
14
15(function(global) {
16
17 String.extend({
18
19 'namespace': function(context) {
20 context = context || global;
21 this.split('.').every(function(s, i) {
22 return !!(context = context[s]);
23 });
24 return context;
25 }
26
27 });
28
29})(this);