Created
May 23, 2012 15:17
-
-
Save thewillk/2775844 to your computer and use it in GitHub Desktop.
Basic Namespacing/Sandboxing System
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
(function(){ | |
var n$, | |
decorate, | |
expand, | |
libraries = [], | |
set_libraries; | |
n$ = function(cb){ | |
if(cb.apply) { | |
cb.apply(n$,libraries); | |
} | |
return n$; | |
} | |
set_libraries = function() { | |
if( arguments.length > 0 ) { | |
libraries = arguments; | |
} | |
return libraries; | |
}; | |
decorate = function(name,value) { | |
var i; | |
if( arguments.length > 1 ) { | |
this[name] = value; | |
} | |
else { | |
for(i in name) { | |
this[i] = name[i]; | |
} | |
} | |
}; | |
expand = function(name){ | |
var i, that = this; | |
if( name && !(name in that) ) { | |
this[name] = function(cb){ | |
if(cb.apply) { | |
cb.apply(that[name],libraries); | |
} | |
return that[name]; | |
}; | |
this[name]['expand'] = function(){return expand.apply(that[name],arguments);}; | |
this[name]['decorate'] = function(){return decorate.apply(that[name],arguments);}; | |
} | |
return this[name]; | |
}; | |
n$['expand'] = function(){return expand.apply(n$,arguments);}; | |
n$['decorate'] = function(){return decorate.apply(n$,arguments);}; | |
n$['libs'] = set_libraries; | |
this['n$'] = n$; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment