Home  >  Article  >  Web Front-end  >  js simple namespace manager example code_javascript skills

js simple namespace manager example code_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:31:56895browse

Copy code The code is as follows:

function $package(name)
{
                 // Split the namespace domain string
       var domains = name.split(".");         var cur_domain = window; var i=0; i< domains.length; i )
{
var domain = domains[i];
//If the domain space has not been created
if(typeof(cur_domain[ domain]) == "undefined")
                                                                                                                        The current domain is the domain of this cycle
            cur_domain = cur_domain[domain]; );
$package("com.hs.test");
with(com.anllin)
with(com.hs)
{
alert("system1 : " system) ;
alert("test1 : " test);
}

//Use 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);
})();




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn