理解CommonJS ,AMD ,CMD, 模块规范

参考 : https://blog.csdn.net/xcymorningsun/article/details/52709608

1、CommonJS 模块规范 (同步加载模块):

 var math = require('math');    // 其中 math 是模块实例
 math.add(2,3); // 5

 

2、 AMD 模块规范  (异步加载依赖模块):

require(['math'], function (math) {   // 其中 math 是模块实例 
 math.add(2, 3);
});

 

3、CMD 模块规范  (异步加载依赖模块) :  CMD 是 淘宝的玉伯大牛搞 了 SeaJS, 在推广过程中对模块定义的规范化产出。基本国内在用 

 

4、这里说到模块规范,es6 中的 import 也是一种模块规范。这里不做过多介绍,在es6分类中会详细介绍。

posted @ 2018-06-10 19:33  吴飞ff  阅读(119)  评论(0编辑  收藏  举报