Seajs is a JavaScript module loading framework that follows the CMD specification, enabling the modular development and loading mechanism of JavaScript.
Unlike JavaScript frameworks such as jquery, SEAJS does not extend the encapsulation language features, but only the modularity of JavaScript and the loading of modules by module. The main purpose of SEAJS is to make JavaScript modular and easy to load, freeing front-end engineers from heavy JavaScript files and object-dependent processing to focus on the logic of the code itself. The SEAJS can be seamlessly integrated with a framework such as jquery. Using SEAJS can improve the readability and sharpness of JavaScript code, solve the problems of dependency confusion and code entanglement commonly existed in JavaScript programming, and facilitate code writing and maintenance.
Html:
<! DOCTYPE html>
Js:
Customizing a module to follow the SEAJS specification define (function (Require, exports, module) { ///Here is the module's private space function Add (A, b) { Return Parsefloat (a) + parsefloat (b); } function Subtract (A, a,) { return parsefloat (a)-parsefloat (b); } Exposing the public member of the module exports.add = add; Exports.subtract = subtract;});
Here through the use of the method to introduce the module, we can also introduce the module through the require, usually JS and JS between the call, this is commonly used.
Convertor.js:
Define (function (require,exports,module) { //exposes some conversion logic Exports.converttonumber = function (input) { return parsefloat (input); }})
Calculator.js:
Define (function (Require, exports, module) { var convertor = require ('./convertor.js '); Here is the private space function of the module Add (b) { return Convertor.converttonumber (a) + Convertor.converttonumber (b); } function Subtract (A, a,) { return Convertor.converttonumber (a)-convertor.converttonumber (b); } Exposing the public member of the module exports.add = add; Exports.subtract = subtract;});
Here is a question, if exports.xxx = xxx, such a way to expose public members in fact are all mounted under the module, if replaced by module.exports = XXX, then will only expose this member variable out. He was the last one to go. You can also expose members using return, with the highest priority for return. In general we do not have to return, but to choose between exports.xxx and Module.exports=xxx.
AngularJS1 notes-(20)-Modular loading mechanism SEAJS