会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
rongfengliang-荣锋亮
js 命名空间
yui的命名空间和继承机制
var
YAHOO
=
window.YAHOO
||
{}
;
YAHOO.namespace
=
function
(ns)
{
if
(
!
ns
||
!
ns.length)
{
return
null
;
}
var
levels
=
ns.split(
"
.
"
);
var
nsobj
=
YAHOO;
//
YAHOO is implied, so it is ignored if it is included
for
(
var
i
=
(levels[
0
]
==
"
YAHOO
"
)
?
1
:
0
; i
<
levels.length;
++
i)
{
nsobj[levels[i]]
=
nsobj[levels[i]]
||
{}
;
nsobj
=
nsobj[levels[i]];
}
return
nsobj;
}
;
YAHOO.extend
=
function
(subclass, superclass)
{
var
f
=
function
()
{}
;
f.prototype
=
superclass.prototype;
subclass.prototype
=
new
f();
subclass.prototype.constructor
=
subclass;
subclass.superclass
=
superclass.prototype;
if
(superclass.prototype.constructor
==
Object.prototype.constructor)
{
superclass.prototype.constructor
=
superclass;
}
}
;
YAHOO.namespace(
"
util
"
);
YAHOO.namespace(
"
widget
"
);
YAHOO.namespace(
"
example
"
);
posted on
2014-03-13 22:14
荣锋亮
阅读(
223
) 评论(
0
)
收藏
举报
刷新页面
返回顶部
导航
博客园
首页
新随笔
联系
订阅
管理
公告