Two specifications for JS modularity amd and CMD

Source: Internet
Author: User

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

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.

Difference:

1. For dependent modules, AMD is executed in advance and CMD is deferred. 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 is highly dependent on the nearest, AMD is highly dependent on the predecessor, for example:

//CMD is recommended by defaultDefinefunction(Require, exports, module) {varA = require ('./a ')) a.dosomething ()//100 lines are omitted here    varb = require ('./b '))     //Reliance can be written nearb.dosomething () ...})//the default recommended by AMD isdefine (['./a ', './b '),function(A, b) {//dependence must be written right from the starta.dosomething ()//100 lines are omitted hereb.dosomething () ...})

It is worth mentioning that require also support the writing of CMD, but it seems that require more recommend this AMD default wording.

3. AMD's API default is one when multiple use, the CMD API is strictly differentiated and respected Single Responsibility。 For example, AMD, require global require and local require, are called require. In CMD, there is no global require, but it provides SEAJS according to the completeness of the module system. UseTo enable the loading of the module system to start. CMD, each API is Simple and pure
4. There are also some details of the difference, the specific definition of the specification is good, not much to say.

JS Modular two specifications AMD and CMD

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.