Created
October 14, 2013 08:27
-
-
Save xiaojue/6972631 to your computer and use it in GitHub Desktop.
module in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//最原始的开发方式 | |
function moduleA(){} // a.js | |
function moduleB(){} // b.js | |
//<script src="a.js"></script> | |
//<script src="b.js"></script> | |
//根据需要手动调整删改a,b...的顺序位置。 | |
//后期又发展为几种高级一些的办法。 | |
//1.老sina包的办法: | |
//app.js | |
$import("a"); | |
$import("b"); | |
a(); | |
b(); | |
//app.js 会被php动态解析用于调试,$import函数就是文件包含功能,不在需要在页面维护模块文件关系。 | |
//优点,实现了模块加载,缺点,需要依赖环境,打包工具,并且并没有真正模块化,而只是碎文件管理,模块依然依赖命名空间来简单粗暴的管理。 | |
//2.前端动态加载,上线使用ant或其他工具进行构建。 | |
someloader("app.js",["a.js","b.js"]); | |
//yui2,dojo ajaxloader等都使用的办法,依然命名空间管理,加载负责调整顺序,注入对应命名方法。 | |
//可以做到开发时,不依赖动态解析环境,如果服务器支持combine,minify,则可自动产生combine文件路径,不需要ant等工具。 | |
//优点,更灵活,缺点,模块化程度不够,模块依赖关系强烈,模块关系需要明文书写。 | |
//可以看出这种方法和amd已经非常接近了。 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment