5-5 ES6的模块化的基本规则或特点

一.AMD, CMD, CommonJs和ES6对比

1.AMD ==> 是RequireJS在推广过程中对模块定义的规范化产出

// RequireJS定义标准, 导步加载依赖, 依赖前置
define(['package/lib'], function(lib){
    function foo(){
        lib.log("hello world!")
    }

    return {
        foo: foo
    }
})

2.CMD ==> 是SeaJS在推广过程中对模块定义的规范化产出

// SeaJS定义标准, 同步加载依赖, 淘宝开发的模块
// 所有模块都通过define来定义
define(function(require, exports, module){
    // 通过 require引入依赖
    var $ = require("jquery");
    var Spinning = require("./spinning");
})

3.CommonJS ==> module.exports node.js后端使用 (浏览器不支持) 

// node.js服务器定义模块化
exports.area = function(r){
    return Math.PI * r * r;
}

exports.circumference = function(r){
    return 2 * Math.PI * r;
}

4.ES6 ==> export/import

原文地址:https://www.cnblogs.com/alantao/p/8335540.html