加载方法如下://定义test.js模块:
define(function (){
var cheng = function (x,y){
return x*y;
};
return {
cheng : cheng
};});
//加载
require(['test'], function (t){
alert(t.cheng (1,1)); //结果为1
});
//定义test.js模块,而test.js模块又依赖other模块:
define(['other'], function(other){
function to(){
//这里这通过other调用other模块的代码
}
return {
to: to
};
});
注:当加载test.js模块时,会先加载它所依赖的other.js模块
联系客服