Requirejs and other learning

Source: Internet
Author: User

Requirejs
JavaScript Modular Programming (AMD&COMMONJS)

The notation of the module

View

AMD Specifications

Currently, there are two types of common JavaScript module specifications: CommonJS and AMD .
In Commonjs, there is a global method require () that is used to load the module. Assuming that a mathematical module is math.js, it can be loaded as follows.

var math = require(‘math‘);

Then, you can invoke the method provided by the module:

var math = require(‘math‘); math.add(2,3); // 5

However, due to a significant limitation, the COMMONJS specification does not apply to the browser environment. or the previous section of the code, if run in the browser, there will be a big problem

var math = require(‘math‘); math.add(2, 3);

The second line, Math.add (2, 3), runs after the first line of require (' math '), so it must wait until the math.js load is complete. That is, if the load time is long, the entire application will stop there and so on.
This is not a problem on the server side, because all the modules are stored on the local hard disk, can be loaded synchronously, waiting time is the hard disk read time. However, for the browser, this is a big problem, because the modules are placed on the server side, the waiting time depends on the speed of the network, it may take a long time, the browser is in "Suspended animation" status.
As a result, the browser-side module cannot be "synchronous-loaded" (synchronous) and can only take "asynchronous load" (asynchronous). This is the background to the birth of the AMD (asynchronous Module Definition) specification.
AMD is the abbreviation for "Asynchronous module definition", meaning "async module definition". It loads the module asynchronously, and the module's load does not affect the execution of the statement behind it. All statements that rely on this module are defined in a callback function that will not run until the load is complete.
Currently, there are two main JavaScript libraries that implement the AMD specification: require.js and curl.js .

Compatibility of COMMONJS specifications and AMD specifications

The COMMONJS specification loading module is synchronous, that is, only the loading is complete before the subsequent operation can be performed. The AMD specification is a non-synchronous loading module that allows you to specify a callback function. Since node. JS is primarily used for server programming, the module files are generally present in the local hard disk, so it is faster to load and do not consider the way of non-synchronous loading, so the COMMONJS specification is more applicable. However, if it is a browser environment, to load the module from the server side, it must be in an asynchronous mode, so the browser side is generally used AMD specifications. From
COMMONJS is a specification, NODEJS is the implementation of this specification. COMMONJS has many implementations, many of which are famous, such as: Apache CouchDB and node.js so on. But most of these projects only implement part of the COMMONJS specification.

node. js

node. JS is a running environment for JavaScript on the server side and a tool library for interacting with other software on the server side. Its JavaScript interpreter, using Google's V8 engine.
Tutorial: http://www.nodebeginner.org/index-zh-cn.html
Http://javascript.ruanyifeng.com/nodejs/basic.html

MVC Framework Angularjs&backbone

http://segmentfault.com/blog/news/1190000000379723
What's the route?

Requirejs and other learning

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.