AMD、CMD、CommonJs和ES6的区别

一、AMD是RequireJs在推广过程中对模块定义的规范化产出。

1 define(['package/lib'],function(lib){
2   function foo(){
3     lib.log("hello world");
4   };
5   return {
6     foo:foo
7   };
8 })

特点是:依赖前置,异步模块定义

二、CMD是SeaJs在推广过程中对模块定义的规范化产出。

1 //所有模块通过defined来定义
2 define(function(require,export,module){
3   //通过require引入依赖
4   var $=require('jqurey');
5   var spinning=require('./spinning');
6 })

特点是:淘宝团队提供,依赖就近,同步概念即用即加载模块。

三、CommonJs规范,module.exports

1 exports.area=function(r){
2   return Math.PI*r*r;
3 }
4 
5 exports.circumference=function(r){
6   return 2*Math.PI*r;
7 }

特点是nodeJs后台采用的规范

四、ES6特性export/import

特点是成对出现,只有到处才能导入。

原文地址:https://www.cnblogs.com/dongdongseven/p/7724106.html