AngularJS1 notes-(20)-Modular loading mechanism SEAJS

Source: Internet
Author: User

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

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.