JavaScript Modular Simple parsing _javascript techniques

Source: Internet
Author: User

This paper explains the modularization of JavaScript, which is as follows:

AMD is requirejs in the promotion process of the modular definition of the standardized output.

Load modules asynchronously, rely on predecessors, execute ahead of time.
Define defines module define ([' Require ', ' foo '],function () {return});
Require loading module (dependent predecessor) require ([' foo ', ' Bar '],function (Foo,bar) {});

CMD is the normalized output of the module defined by SEAJS in the process of popularization.

Define defines exports export define (function (Require,exports,module) {}); Some objects on the current module are stored on modules.
Require (. A) is introduced directly. Require.async Asynchronous Introduction.
Synchronous loading, relying on proximity, delaying execution.

The application of Seajs

Official Introductory Example: http://seajs.org/docs/#quick-start

How to write a Seajs module?

All modules are defined by define to define
define (function (Require, exports, module) {
 
 //via require to introduce dependent
 var $ = require (' jquery ') ;
 var spinning = require ('./spinning ');
 
 Through exports to provide external interface
 exports.dosomething = ...
 
 or provide the entire interface
 Module.exports = ...} via Module.exports
 
;

load a module in a page

At the end of the Hello.html page, after introducing sea.js through the script, there is a section of configuration code:
 
//Seajs Simple configuration
seajs.config ({
 base:). /sea-modules/",
 alias: {
  " jquery ":" Jquery/jquery/1.10.1/jquery.js "
 }
})
 
//Loading Portal Module
Seajs.use (".. /static/hello/src/main ")

The above is a brief introduction to JavaScript modularity, and I hope it helps to learn JavaScript modularity.

Related Article

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.