Regarding the CMD specification and AMD specification in the industry, has the great god explained the relationship with conmm.js? common.js is a set of framework and specifications, and is only a specification.

  node.js, question

Recently, I consulted the relevant information about AMD and CMD modular loading on the Internet. As far as ADM is concerned, my current understanding is that require.js is following the common.js standard, while CMD is sea.js. I am a novice. Great God Kneel to beg can explain it to me and let me understand!

AMD and CMD
The copyright belongs to the author.
For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
Author: Yubo
Links:https://www.zhihu.com/question/20351507/answer/14859415
Source: Zhihu

AMD specifications are here:https://github.com/amdjs/amdjs-api/wiki/AMD
CMD specifications are here:https://github.com/seajs/seajs/issues/242

AMD is a standardized output of module definition by RequireJS in the promotion process.
CMD is the standardized output of SeaJS’s module definition in the promotion process.
Similarly, CommonJS Modules/2.0 specification is the standardized output of BravoJS’s module definition in the promotion process.
There are many more.

The purpose of these specifications is to develop JavaScript modularly, especially on the browser side.
At present, the realization of these specifications can achieve the goal of modular development of browser.

Difference:

  1. For dependent modules, AMD executes ahead of schedule and CMD delays execution. However, RequireJS starts from 2.0 and can be delayed (depending on the writing method, the processing method is different). CMD praises as lazy as possible.

  2. CMD advocates reliance on proximity, AMD advocates reliance on proximity. Look at the code:

// CMD
define(function(require, exports, module) {
var a = require(‘./a’)
a.doSomething()
//Omit 100 lines here
Var b = require(‘./b’) // dependencies can be written nearby
b.doSomething()
// …
})

// AMD recommends by default
Define ([‘./a’,’ b’], function (a, b) {//dependencies must be written from the beginning
a.doSomething()
//Omit 100 lines here
b.doSomething()

})

Although AMD also supports the writing of CMD and passing require as a dependency, the author of RequireJS likes the above writing by default and is also the default module definition writing in the official document inside.

  1. AMD’s API is one for multiple uses by default. CMD’s API is strictly distinguished and advocates single responsibility. For example, AMD inside, require is divided into global require and local require, both called require. CMD inside does not have a global requirement, but provides seajs.use according to the completeness of the module system to require the loading and starting of the module system. CMD inside, every API is simple and pure.

Sea.JS and Require.JS

Same place

RequireJS and Sea.js are both module loaders, advocating the concept of modular development. The core value is to make modular development of JavaScript simple and natural.

Different places

The main differences between the two are as follows:

  • There are differences in positioning. RequireJS wants to be a module loader on the browser side, and also wants to be a module loader in Rhino/Node and other environments. Sea.js focuses on the Web browser side, and can easily run in the Node environment through Node extension.

  • The standards followed are different. RequireJS follows AMD (asynchronous module definition) specification and Sea.js follows CMD (common module definition) specification. The difference in specifications leads to the difference in API between the two. Sea.js is closer to CommonJS Modules/1.1 and Node Modules specifications.

  • There are differences in promotion concepts. Requirjs is trying to get third-party class libraries to modify themselves to support Requirjs, which is currently adopted by only a few communities. Sea.js does not push forward strongly and adopts the method of independent packaging to “acce pt all rivers into the sea”. At present, there are relatively mature packaging strategies.

  • There are differences in support for development and debugging. Sea.js pays close attention to the development and debugging of codes, and has plug-ins such as nocache and debug for debugging. RequireJS has no obvious support in this regard.

  • The plug-in mechanism is different. RequireJS takes the form of reserving interfaces in the source code, and the plug-in type is relatively single. Sea.js adopts a common event mechanism and has more plug-in types.

There are still many differences, involving specific usage and source code implementation. Interested parties are welcome to study and express their views.

In a word, if RequireJS is the Prototype class library, Sea.js is committed to becoming jQuery class library.

Most important

Finally, pay tribute to RequireJS! RequireJS and Sea.js are good brothers, and work together to promote the idea of modular development, which is the most important thing.