Comparison between SeaJS and RequireJS _ AngularJS

Source: Internet
Author: User
This article mainly introduces the differences between SeaJS and RequireJS. This article compares the disadvantages of the CMD and AMD specifications and makes a summary, for more information, see "History is not in the past and history is ongoing. With the rapid development of W3C specifications and browsers, front-end modular development will gradually become the infrastructure. Everything will eventually become history, and the future will be better ." -- I personally agree with the last passage of the original yuber article. Now that we have talked about the "future", I personally think that if the front-end js module continues to develop, its module format will likely become a standard specification for the Future WEB and will generate multiple implementation methods. Just like the JSON format, it eventually becomes a standard and implemented by the browser native.

Who will be the future standard of asynchronous modules? SeaJS follows the CMD specification, and RequireJS follows the AMD specification, starting with these two different formats.

CMD

CMD module dependency declaration method:

The Code is as follows:


Define (function (require ){
Var a = require ('./');
Var B = require ('./B ');
// More code ..
})

CMD dependency is declared nearby and declared through the internal require method. However, because it is an asynchronous module, the loader needs to load these modules in advance, so all dependencies in the module need to be extracted before the module is actually used. Whether it is immediate extraction by the loader or pre-extraction by automated tools, the dependency declaration format of CMD can only be implemented through static analysis, which is also the disadvantage of CMD.

Disadvantages of CMD specifications

Cannot be directly compressed: require is a local variable, meaning that it cannot be compressed directly using a compression tool. If require is replaced, the loader and automation tool will not be able to obtain the module dependency.
There is an additional convention in writing the module: path parameters cannot be used for string operations, but cannot be replaced by variables. Otherwise, the loader and automation tools cannot correctly extract the path.
Conventions outside of the specification mean more documentation, unless they are part of the Specification.

Note: The Static Analysis of SeaJS is implemented by extracting the require part of the module package toString () and using regular expressions to obtain the dependent module path.

AMD

AMD module dependency declaration method:

The Code is as follows:


Define (['./A','./B '], function (a, B ){
// More code ..
})

AMD's dependency is declared in advance. The advantage of this advantage is that dependency does not need to be analyzed through static analysis. Both the loader and the automation tool can directly obtain the dependency, and the standard definition can be simpler, this means that more powerful implementations may be generated, which is advantageous for the loaders and automated analysis tools.

Disadvantages of AMD specifications

Dependency declaration is not so friendly in code writing.
The Modules are different from those of NodeJS.
The second question should be explained in detail. In fact, both the CMD and AMD asynchronous Modules cannot be consistent with the synchronization module specifications (node. js Modules). Only one is more like a synchronization module than the other. To convert AMD to a synchronization module, in addition to removing the define function package, you need to use require in the header to declare the dependency, while CMD only needs to remove the define function package.

Summary

In terms of standards, AMD is simpler and more rigorous, and has a wider applicability. With the powerful support of RequireJS, AMD standards have almost become a de facto asynchronous module standard in foreign countries.

However, SeaJS and CMD have done a lot of good things:

1. Relatively natural dependency declaration Style
2. small and beautiful internal implementation
3. Intimate peripheral Function Design
4. Better Chinese Community Support

If possible, I would like to see that SeaJS also supports AMD. What makes the ultimate happiness consistent with the front-end community environment is that the majority of developers.

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.