Last active
August 29, 2015 14:01
-
-
Save marsen/d6c66e8cd6f1620cf56f to your computer and use it in GitHub Desktop.
namespace pattern (命名空間模式)
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 pattern | |
var MYAPP = MYAPP || {}; | |
MYAPP.namespace = function(ns_string){ | |
var parts = ns_string.split('.'), | |
parent = MYAPP, | |
i; | |
if(parts[0]==="MYAPP"){ | |
parts = parts.slice(1); | |
} | |
for(i=0;i<parts.length;i+=1){ | |
if(typeof parent[parts[i]] === "undefined") { | |
parent[parts[i]] = {}; | |
} | |
parent = parent[parts[i]] ; | |
} | |
return parent; | |
}; | |
//namespace pattern demo | |
MYAPP.namespace("MYAPP.Tools.ZipComponent"); | |
console.log(MYAPP); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment