Require.js "Modular Programming"-simple example of module loading

Source: Internet
Author: User

Today I learned a bit about JavaScript's modular programming and wrote a simple example.

———————————————— This is my first technical little blog post, I hope to communicate with you ————————————————

I'm going to make a list of two parts:

1. File map

2. Source CodeDemo.html:
1 <!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">2 <HTMLxmlns= "http://www.w3.org/1999/xhtml">3 <Head>4 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />5 <title> Module Loading simple example </title>6  <script  data-main= "main"  type= "Text/javascript"  src= "Require.js"></script> 78 </Head>9 <Body>Ten Empty page One </Body> A </HTML>

A.js

var function (numa,numb) {    return NumA + NumB;}

B.js

// Subtraction var function (numa,numb) {    return NumA- NumB;} // Division Object function Glindiv (divisor) {    this. Divisor = divisor;         This function (num) {        returnthis. divisor;    }}

C.js

// multiplication var function (num,ples) {    return num * ples;} // example Chemical control method for image New /* = = = This depends on the Glindiv object defined in b.js = = */

Main.js

//Module Load Path configurationRequire.config = {    "A": "A",    "B": "B",    "C": "C"}//The order in which the modules are loaded and the-----------of the callback function (where "C" must be after "B", because the "//instance Chemical control" in "C" for "//Division Object" in "dependent" B ")Require (["A", "B", "C"],function(a,b,c) {varNUM01 = 10; varNUM02 = 20; varPels = 2; //call the function in the loaded module to perform the Operation     varTol =rsub (Radd (NUM01,NUM02), Rmul (Num01,pels)); Alert (Mydiv.rdiv (tol));//pop-up window test  });

Require.js (Tool library, own Baidu)

Conclusion: Welcome all students to exchange guidance, especially hope to get some good blog presentation and display ways of advice!

Require.js "Modular Programming"-simple example of module loading

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.