Commonjs,amd,cmd specification

Source: Internet
Author: User


1. Javascript inherently lacks the functionality of the module. In other high-level languages, Java has a class file, Python has an import mechanism, Ruby has require,php include and require, and JavaScript needs to rely on <script> tags to introduce code, When the script is many, it will appear disorganized.

2. In response to the above problems, Commonjs emerged. COMMONJS has a vision for javascript: to be able to run anywhere! (not just for browser), Commonjs wants to make up for JavaScript without standard flaws (no modular system, fewer standard libraries, no standard interfaces, no package management system), and can write large applications such as server-side JavaScript, command-line tools, Desktop graphical interface applications, hybrid applications, and more.

3. The CommONJS specification covers:

module, binary Buffer , Character set encoding, I/O flow, process environment, file system, sockets, Web Server network Management interface, package administration and so on.

4. Node. JS follows the COMMONJS specification and advances the development of Commonjs .

5. CommOnjs is mainly for JS in the back end of the performance of the formulation, not suitable for the front end. Why do you say that?

The front-end JavaScript is placed on both ends of the HTTP , each of which plays a different role:



browser-side Java Script

Server-Side Java Script

Execution of code Need to experience distribution from the same server side to multiple client executions The same code needs to be executed multiple times

Bottleneck

is the bandwidth

is that CPU and Memory Resources

How code is loaded

Need to load code over the network

Load code from disk (both speed not at one order of magnitude)

6. AMD appeared,Asynchronous module definition. Asynchronous module definitions.

It is mainly for the front-end JS performance Norm .

AMD specification has only one API , its module is defined as follows:

DeFine (id?,dependencies?,factory);//id,dependencies optional, factory content is the content of the actual code.

A. ID: module identification, can be omitted, here the module identifier refers to itself, that is, the entire file. So when the ID is omitted, it is equivalent to defining an anonymous module, when the module filename is the module identifier. e.g. the module file is placed in A.js, then A is the module name.

B. dependencies: Dependency module. the AMD specification specifies all dependencies when declaring the module, and also as a parameter to the factory . For example:

define ([' Dep1 ', ' dep2 '], function (DEP1, DEP2) {...});

An example that does not include a dependency relationship:

define (function () {

var exports = {};

Exports.method = function () {...};

return exports;

...

});


c.  from d Span style= "line-height:0px;" > efine function is not difficult to think of define The function has an asynchronous nature. When it executes, it first asynchronously invokes the dependent module listed in the second parameter, and executes if the third parameter is a callback function when all the modules are loaded.

D. in node. js , you don't see the define module wrapped up because node The implicit packaging is implemented (i.e. when the module is at compile time,nodemodules are packaged to isolate each module file to prevent variable contamination).

E. Requirejs is the implementation of the AMD specification.


7. The CMD specification is presented by the Yuber in the country and differs from the AMD specification in the definition of modules and dependencies introduced in the section. The style is closer to Node. You can look at sea.js.

Commonjs,amd,cmd specification

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.