Home > Web Front-end > JS Tutorial > body text

js simple namespace manager example code_javascript skills

WBOY
Release: 2016-05-16 17:31:56
Original
899 people have browsed it

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




Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template