Naming conflicts and file dependencies are two classic problems in front-end development. Through modular development to solve.

The AMD specification is here: github.com/amdjs/amdjs…

The CMD specification is here: github.com/seajs/seajs…

AMD is the canonical output of RequireJS’s module definition in its promotion process. CMD is the normalized output of SeaJS module definitions during the roll-out process.

Similarly, there is the CommonJS Modules/2.0 specification, which is the normalized output of the module definition in the promotion process of BravoJS.

There are a lot of

These specifications are aimed at modularizing JavaScript development, especially on the browser side. At present, the implementation of these specifications can achieve the purpose of browser side modular development.

The difference between:

1, for dependent modules, AMD is early execution, CMD is delayed execution. Since 2.0, however, RequireJS has also been deferred (handled differently depending on how it is written). CMD advocates as lazy as possible.

2, CMD advocates relying on nearby, AMD advocates relying on the front. Look at the code:

// CMD define(function(require, exports, Module) {var a = require('./a') a.dosomething (); var b = require('./b');  }) / / AMD recommended by default is to define (['. / a ', '/' b], function (a, B) {// Dependencies must start with a.dosomething () // 100 lines omitted here b.dosomething ()... })Copy the code

Although AMD also supports CMD and requires as a dependency, RequireJS authors prefer it by default and it is the default module definition in the official documentation.

3, AMD API default is a when multiple use, CMD API strictly differentiated, advocating a single responsibility. For example, in AMD, require is divided into global require and local require, both called require. In CMD, there is no global require, but according to the completeness of the module system, seajs.use is provided to realize the loading and starting of the module system. In CMD, every API is simple and pure.

4. There are still some differences in details, which will depend on the definition of this specification. In addition, the differences between SeaJS and RequireJS can be found at github.com/seajs/seajs…