JavaScript Modular Programming-Specifications

Source: Internet
Author: User

While it is important to implement JavaScript modularity, how can we achieve modularity that is internationally acceptable? Modular programming specification comes into being.

There are two main types of JavaScript modularity: Commonjs and AMD.

CommonJS:

In 09, US program developer Ryan Dahl created the node. JS project to use JS on the server side.

Because of the complex business of the backend service side, if there is no modular programming specification, background maintenance and development will become extremely difficult.

Node. JS's module system is implemented with reference to the COMMONJS specification. In Commonjs, require () is used to load the module.

Require () can only be loaded synchronously, so the browser side due to the speed limit, will cause the browser suspended animation, so the limitations of this specification can only be applied to the server side.

Amd:

AMD is the abbreviation for "Asynchronous module definition", which explains "asynchronous module definition" in Chinese. This specification, the use of asynchronous loading module, and background server multithreading somewhat similar.

This specification, all modules involved, will have a definition of a callback function. It can be understood that the callback function will not execute until the loading is complete.

Eg:

Require ([module],callback);

The first parameter, [module], is an array, the member is the module that needs to be loaded, and the second parameter [callback] is the callback function after the successful load.

Libraries currently implementing AMD Specifications: Require.js and Curl.js.

JavaScript Modular Programming-Specifications

Related Article

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.