Simple parsing of javascript modularization and javascript Modularization
This article explains the modularization of javascript as follows:
AMDThis is the standardized output defined by RequireJS in the promotion process.
Asynchronously load the module, depending on the front, and execute it in advance.
Define definition module define (['require ', 'foo'], function () {return });
Require loading module (dependent on the front) require (['foo', 'bar'], function (foo, bar ){});
CMDThis is the standardized output defined by SeaJS in the promotion process.
Define defines exports to export define (function (require, exports, module) {}); the module stores some objects on the current module.
Directly introduce require (./. Require. async asynchronous introduction.
Synchronous loading with nearby dependencies and delayed execution.
SeaJS Application
Official Entry Example: http://seajs.org/docs/#quick-start
How to Write a SeaJS module?
// All modules use define to define (function (require, exports, module) {// introduce the dependency var $ = require ('jquery ') through require '); var Spinning = require ('. /spinning '); // provides the interface exports through exports. doSomething =... // or use module. exports provides the entire interface module. exports = ...});
In the pageLoad Module
// At the end of hello.html, use the script to introduce sea. after js, there is a piece of configuration code: // seajs simple configuration seajs. config ({base :".. /sea-modules/", alias: {" 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 modularization, hoping to help you learn about javascript modularization.
Articles you may be interested in:
- Javascript Modular programming (I) Best practices for writing modules
- Javascript Modular programming (I) AMD specifications (standard use module)
- Javascript Modular programming (iii) Introduction to the usage and functions of require. js
- Modularization of JavaScript: encapsulation (closure), inheritance (prototype) Introduction
- What is javascript modularization and its advantages and disadvantages
- Javascript Modular programming
- In-depth exploration of seajs modularization and Loading Methods
- SeaJS for JavaScript modular Development