AMD CMD 区别
sea.js(CMD) 模块定义
define(function(require, exports, module) {
console.log('sea_test2');
//type2
var a = {};
a.doSomething = function(){
console.log("sea_test2 doSomething");
};
// 或者通过 module.exports 提供整个接口
module.exports = a;
});
define(function(require, exports, module) {
// 通过 require 引入依赖
require('./sea_test2.js');
// type1
// 通过 exports 对外提供接口
// exports.doSomething2 = function(){
// console.log("do2");
// };
//type2
var a = {};
a.doSomething = function(){
console.log("sea_test1 doSomething");
};
// 同时出现 后面覆盖前面
// 或者通过 module.exports 提供整个接口
module.exports = a;
});
require.js(AMD) 模块定义
define(function() {
//type2
var a = {};
a.doSomething = function(){
console.log("require_test2 doSomething");
};
// 通过 return 提供整个接口
return a;
});
define(['./require_test2.js'],function(test2) {
test2.doSomething();
//type2
var a = {};
a.doSomething = function(){
console.log("require_test1 doSomething");
};
// 通过 return 提供整个接口
return a;
});
依赖文件定义位置 方法不一样 加载方式不一样 接口抛出方式不一样
RequireJS 是没有明显的 bug,SeaJS 是明显没有 bug