This article explains the modularity of javascript for you. The specific content is as follows
AMD is the standardized output of module definition by RequireJS during the promotion process.
Asynchronously loads the module, depends on pre-installation, and executes in advance.
Define definition module define(['require','foo'],function(){return});
Require loading module (depends on pre-set) requires(['foo','bar'],function(foo,bar){});
CMD is the standardized output of SeaJS's module definition during the promotion process.
Define definition exports export define(function(require,exports,module){}); Some objects on the current module are stored on the module.
require(./a) is introduced directly. Require.async is introduced asynchronously.
Synchronous loading, dependency is near, delayed execution.
SeaJS application
Official introduction example: http://seajs.org/docs/#quick-start
How to write a SeaJS module?
// All modules define define(function(require, exports, module) { // Introduce dependency var through require $ = require('jquery'); var Spinning = require('./spinning'); // Provide the interface to the outside through exports exports.doSomething = ... // Or provide the entire interface through module.exports module.exports = ... });Loading modules in page
//At the end of the hello.html page, after introducing sea.js through script, there is a configuration code: // simple configuration of seajs seajs.config({ base: "../sea-modules/", alias: { "jquery": "jquery/jquery/1.10.1/jquery.js" }}) // Load the entry module seajs.use("../static/hello/src/main")The above is a brief introduction to JavaScript modularity. I hope it will be helpful to everyone to learn JavaScript modularity.