AMD /CMD

Transition modular development ideas

AMD:require.js

CMD:sea.js

AMD is RequireJS module specification defined in the promotion process.
CMD is SeaJS module specification defined in the promotion process.

the difference:

1. For the dependent modules, AMD is executed in advance, CMD is deferred execution. However RequireJS from 2.0, can also be changed to perform delay (depending on the wording handled differently). CMD respected as lazy as possible.

2. CMD respected rely nearby, AMD respected front-dependent. Look at the code:

// AMD is the recommended default
define ([ './ a', './b'], function (a, b) {// must rely outset written
a.doSomething ()
// omitted here 100 lines
b.doSomething ()
...
})

The CMD //
DEFINE (function (the require, Exports, Module1) {
var A = the require ( './ A')
a.doSomething ()
// 100 rows omitted here
var b = require ( './ b ') / / dependency can be written nearby
b.doSomething ()
// ... 
})

Although AMD also supports the wording of CMD, and also supports dependency will require a transfer, but the author's favorite RequireJS default is written above, it is the official document in the default module definition wording.

 

3. AMD's API is a default when multiple use, CMD of the API strictly separated respected single responsibility. For example, in AMD, require points require global and local require, call require. CMD, no global require, but according to the completeness of the system module, providing seajs.use to achieve load startup module system. CMD, each API is simple and pure.

 

Guess you like

Origin www.cnblogs.com/xinxinxiangrong7/p/11456562.html
AMD
cmd