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.