Created
October 11, 2012 21:12
-
-
Save obenjiro/3875521 to your computer and use it in GitHub Desktop.
Vanilla Namespace Pattern #1 (96 chars)
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
//namespace patter #1 - with comments | |
(function(window, lastObject, private_n){ | |
private_n = function(namespace){ | |
lastObject = lastObject[namespace] = lastObject[namespace] || {}; | |
return private_n; | |
} | |
window.n = function(namespace){ | |
lastObject = window; | |
return private_n(namespace) | |
} | |
})(this); | |
//namespace patter #1 - obfuscated (96 chars) | |
!function(a,b,c){c=function(a){return b=b[a]=b[a]||{},c},a.n=function(d){return b=a,c(d)}}(this) | |
//namespace patter #1 - usage | |
n("system")("drawing"); | |
system.drawing.doIt = function(){}; | |
n("system")("net"); | |
system.net.constant = "const"; | |
console.log(system.drawing.doIt); | |
console.log(system.net.constant); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment