1.0.4 • Published 5 years ago

xy-demo v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

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

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago