The difference between CMD and AMD (JS Modular)

Source: Internet
Author: User

AMD is the normalized output of the module defined by REQUIREJS during the promotion process.
CMD is the normalized output of the module defined by SEAJS in the process of generalization.
Similar to the CommonJS modules/2.0 specification, is bravojs in the promotion process of the module definition of standardized output.
A lot more??

These specifications are intended for the modular development of JavaScript, especially on the browser side.
At present, the implementation of these norms can be achievedThe purpose of browser-side modularization development

Difference:

1. For dependent modules, AMD isEarly Execution, CMD isdeferred execution。 However, starting from 2.0, Requirejs is also changed to be deferred (depending on the way it is written and handled differently). CMD respected as lazy as possible.

2. CMD respectedrely on the nearest, AMD respectedrelying on the predecessor。 Look at the code:

Cmd
Define (function (Require, exports, module) {
var a = require ('./a ')
A.dosomething ()
100 lines are omitted here
var B = require ('./b ')//dependency can be written near
B.dosomething ()
// ...
})

The default recommended by AMD is
define (['./a ', './b '), function (A, B) {//dependencies must be written at the beginning.
A.dosomething ()
100 lines are omitted here
B.dosomething ()
...
})

While AMD supports the syntax of CMD, it also supports passing require as a dependency, but Requirejs's author defaults to the preferred notation, which is the default definition of the module in the official document.


3. AMD's API default isone when multiple use, the CMD API is strictly differentiated and respectedSingle Responsibility。 For example, AMD, require global require and local require, are called require. In CMD, there is no global require, but according to the completeness of the module system, provide seajs.use to realize the loading and starting of the module system. CMD, each API isSimple and pure


4. There are also some details of the difference, the specific definition of the specification is good, not much to say.

In addition, SEAJS and Requirejs differences, you can refer to:https://github.com/seajs/seajs/issues/277

The difference between CMD and AMD (JS Modular)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.