Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
The introduction of AMD
The COMMONJS AMD specification only defines a global approach, as shown in Listing 1.
Listing 1. AMD Specifications
define (ID, dependencies, Factory);
The ID represents the identity of the module, which is an optional parameter.
Dependencies is a string Array that represents all the other module identities that the module relies on, which must be resolved before the actual execution of the specific factory method, which loads the returned value after execution, and can be used as the default in the order of the factory method. Dependencies is also an optional parameter, when the user does not provide this parameter, the implementation of AMD framework should provide the default value is ["Require", "exports", "module"].
Factory is a method for executing a module that can use the return value of other dependent modules declared in the previous dependencies as a parameter, and if the method has a return value, the return value is the output of the module when it is dependent on another module.
COMMONJS in the specification does not specify other methods, some major AMD frameworks such as Requirejs, curl, bdload and so on are implemented define method, and each framework has its own complement to make its API more practical.
The latest version of Requirejs 1.0.8 works well in IE 6+, Firefox, Safari 3.2+, Chrome 3+, Opera 10+.
Actual Combat Requirejs
Using Requirejs in WEB applications
Download the latest version of Require.js on the Requirejs official homepage and put it on the Web page. The WEB project structure of the sample is shown in Figure 1.
Figure 1. WEB Project Structure
By adding a <script> tag to the index.html, the require.js can be introduced directly.
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to firstname.lastname@example.org. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.