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