标签:blog http io 使用 java ar for 文件 div
运用了命名空间(Namespace)模式后, 就可以使用一些JavaScript库了,比如YAHOO作用YUI2库的全局对象,可以通过 YAHOO.util.Dom 和 YAHOO.util.Event得到YUI2库中有关Dom和事件的支持。在程序中使用这些模块就是声明依赖(Declaring Dependencies)模式:
var myFunction = function () {
//dependencies
var event = YAHOO.util.Event,
dom = YAHOO.util.Dom;
//use event and dom variables
//for the rest of the function...
};
function test1() {
alert(MYAPP.modules.m1);
alert(MYAPP.modules.m2);
alert(MYAPP.modules.m51);
}
/*
minified test1 body:
alert(MYAPP.modules.m1);alert(MYAPP.modules.m2);alert(MYAPP.modules.m51)
*/
function test2() {
var modules = MYAPP.modules;
alert(modules.m1);
alert(modules.m2);
alert(modules.m51);
}
/*
minified test2 body:
var a=MYAPP.modules;alert(a.m1);alert(a.m2);alert(a.m51)
*/
JavaScript基础对象创建模式之声明依赖模式(023)
标签:blog http io 使用 java ar for 文件 div
原文地址:http://www.cnblogs.com/Bryran/p/3976139.html