js简易namespace管理器 实例代码
时间:2024-04-22 13:23:36
function $package(name)
{
//拆分名字空间域字符串
var domains = name.split(".");
var cur_domain = window;
//循环遍历每一级子域
for(var i=0; i< domains.length; i++)
{
var domain = domains[i];
//如果该域的空间未被创建
if(typeof(cur_domain[domain]) == "undefined")
{
//创建域
cur_domain[domain] = {};
}
//设置当前域为此次循环的域
cur_domain = cur_domain[domain];
}
return cur_domain;
};
//用with引用的方式
$package("com.anllin.system");
$package("com.hs.test");
with(com.anllin)
with(com.hs)
{
alert("system1 : " + system);
alert("test1 : " + test);
}
//用闭包引用的方式
$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);
})();
标签:namespace,管理器
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
利用Psyco提升Python运行速度
2021-05-02 19:02:50
关于javascript中伪数组和真数组的一些小秘密
2023-07-02 03:47:47
![](https://img.aspxhome.com/file/2023/5/136125_0s.jpg)
如何取得表中字段的属性?
2010-01-18 20:52:00
python添加命令行参数的详细过程
2022-03-18 15:34:27
![](https://img.aspxhome.com/file/2023/9/114629_0s.png)
python使用post提交数据到远程url的方法
2023-11-12 07:10:19
Vue用v-for给循环标签自身属性添加属性值的方法
2024-04-10 10:30:56
![](https://img.aspxhome.com/file/2023/3/139773_0s.png)
如何在Python对Excel进行读取
2022-02-25 15:51:59
![](https://img.aspxhome.com/file/2023/9/115679_0s.png)
一键安装mysql5.7及密码策略修改方法
2024-01-22 05:29:37
升级到mysql-connector-java8.0.27的注意事项
2024-01-22 20:52:08
![](https://img.aspxhome.com/file/2023/7/112647_0s.png)
JetBrains PyCharm(Community版本)的下载、安装和初步使用图文教程详解
2023-07-13 11:20:21
![](https://img.aspxhome.com/file/2023/5/78825_0s.jpg)
简单的Python人脸识别系统
2023-01-26 23:31:57
SQL查询服务器下所有数据库及数据库的全部表
2024-01-18 22:55:01
![](https://img.aspxhome.com/file/2023/6/119236_0s.png)
Go语言的变量定义详情
2024-04-27 15:41:03
Python环境管理virtualenv&virtualenvwrapper的配置详解
2021-09-28 01:08:08
![](https://img.aspxhome.com/file/2023/4/105704_0s.png)
轻松接触SQL Server 2000实例的命名规则
2009-01-23 13:44:00
简单分析python的类变量、实例变量
2022-12-20 20:39:56
浅谈Golang 切片(slice)扩容机制的原理
2024-04-29 13:06:20
php实现的CSS更新类实例
2023-11-21 22:28:30
python去除扩展名的实例讲解
2022-05-08 18:10:49
asp,php,.net使用301重定向方法
2007-09-26 14:05:00