JavaScript模块化设计模式:AMD、CommonJS与UMD详解
1. AMD模块系统
1.1 使用curl.js加载AMD模块
可以使用 curl.js 来加载AMD模块,示例代码如下:
curl(["app/myModule.js"],
function( myModule ){
// start the main module which in turn
// loads other modules
var module = new myModule();
module.doStuff();
});
1.2 具有延迟依赖的模块
以下是具有延迟依赖的模块代码示例:
// This could be compatible with jQuery's Deferred implementation,
// futures.js (slightly different syntax) or any one of a number
// of other implementations
define(["lib/Deferred"], function( Deferred ){
var defer = new Deferred();
require(["lib/templates/?index.html","lib/data/?stats
超级会员免费看
订阅专栏 解锁全文
14

被折叠的 条评论
为什么被折叠?



