Skip to content

Instantly share code, notes, and snippets.

@obenjiro
Last active October 13, 2015 03:38
Show Gist options
  • Save obenjiro/4133686 to your computer and use it in GitHub Desktop.
Save obenjiro/4133686 to your computer and use it in GitHub Desktop.
Namespace Pattern #3 (82 chars)
//namespace patter #3 - with comments
this.n = function(s, array, lastItem) {
if (array) n(s[array = lastItem.shift()] = s[array] || {}, array, lastItem);
else if (!lastItem) n(this, 1, s.split('.'));
}
//namespace patter #3 - obfuscated (82 chars)
this.n=function(a,b,c){b?n(a[b=c.shift()]=a[b]||{},b,c):c||n(this,1,a.split("."))}
//namespace patter #3 - 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