Function $ package (name)
{
// Split the namespace domain string
Var domains = name. split (".");
Var cur_domain = window;
// Cyclically traverse each subdomain
For (var I = 0; I <domains. length; I ++)
{
Var domain = domains [I];
// If the space of this domain is not created
If (typeof (cur_domain [domain]) = "undefined ")
{
// Create a domain
Cur_domain [domain] = {};
}
// Set the current domain as the domain of this loop
Cur_domain = cur_domain [domain];
}
Return cur_domain;
};
// Use the with reference method
$ Package ("com. anllin. system ");
$ Package ("com. hs. test ");
With (com. anllin)
With (com. hs)
{
Alert ("system1:" + system );
Alert ("test1:" + test );
}
// Use the closure Reference Method
$ Package ("com. anllin. system ");
$ Package ("com. hs. test ");
(Function (){
Var system = com. anllin. system;
Var test = com. hs. test;
Alert ("system2:" + system );
Alert ("test2" + test );
})();
Source of Water