Revisions
-
arboleya revised this gist
Jan 6, 2013 . 2 changed files with 17 additions and 25 deletions.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 @@ -1,25 +0,0 @@ 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,17 @@ /* USAGE: # at window ns( 'my.namespace' ).MyClass = ... # at app obj var app = {} ns( 'my.namespace', app ).MyClass = ... */ function ns( ns, base ) { var n, b = base || window, r = /[^\.]+/g; while( (n = r.exec( ns ) ) != null ) b = b[n[0]] || (b[n[0]] = {}); return b; } -
giuliandrimba revised this gist
Dec 6, 2012 . 1 changed file with 1 addition and 2 deletions.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 @@ -1,6 +1,6 @@ function namespace(name) { var namespaces = name.split("."); var name = ""; function getName(parent) @@ -18,7 +18,6 @@ function namespace(name) } else { return parent; } } -
giuliandrimba created this gist
Dec 6, 2012 .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,26 @@ function namespace(name) { var namespaces = name.split("."); var name = ""; function getName(parent) { if(namespaces.length > 0) { name = namespaces.shift(); if(!parent[name]) { parent[name] = {} } return getName(parent[name], namespaces) } else { obj = parent; return parent; } } return getName(window); }