1.0.4 • Published 5 years ago
xy-demo v1.0.4
CommonJS、AMD、CMD以及ES6的模块系统
CommonJS 加载的是一个对象(即module.exports属性),ES6 模块不是对象,它的对外接口只是一种静态定义 CommonJS 模块输出的是一个值的拷贝,ES6 模块输出的是值的引用
CommonJS Node.js/Webpack 同步 服务器读取本地文件
module、exports、require、global
AMD 异步模块定义 依赖前置 客户端网络假死
define(id?, dependencies?, factory);
CMD 同步模块定义 依赖就近 SeaJS
// File:greet.js
define(function (require, exports) {
function helloPython() {
document.write("Hello,Python");
}
function helloJavaScript() {
document.write("Hello,JavaScript");
}
exports.helloPython = helloPython;
exports.helloJavaScript = helloJavaScript;
});
// File:usegreet.js
sea.use("greet", function (Greet) {
greet.helloJavaScript();
});
ES6
export\import