"Front-end coding" modular programming

Source: Internet
Author: User

Summary:

Slowly began to use modular programming, learning to use define,require this kind of things. The first use of simply feel that the page load will immediately request loading all the files will affect the speed, the later use of the discovery, but also to resolve the interdependence between the files, to resolve the issue of file on-line version.

Continue to find yourself learning is still very shallow, online read this article http://blog.chinaunix.net/uid-26672038-id-4112229.html in-depth understanding under.

First, why to use modular programming

1) Decoupling the complexity of the software system, so that the maintenance of "rational to follow"

2) define package, follow low coupling high cohesion

3) Resolving dependencies between files

4) Fix file load version cache issue

Note:

There are two types of dependencies, "strong dependencies"--certain needs and "weak dependencies"--that may be needed.
For strong dependencies, if performance is a priority, consider relying on a pre-dependent thought design, a person who is more highly respected, able to clearly understand file dependencies, and if you consider development costs first, consider depending on the idea of proximity.
For weak dependencies, you only need to overwrite the weakly dependent portions into the callback function.

Second, the specification

Difference Represent
Amd

Asynchronous module definition, pre-loading, loading dependent modules before using modules.

Format: Define (ID, dependencies, Factory);

Requirejs

Requirejs2.0+ can also support lazy loading

Cmd

The module is loaded only when it is used, and the required asynchronous load module can be loaded using Require.async.

Format: Define (ID, deps, factory);

Require is the first parameter of factory.

Seajs

Three, Requirejs and seajs difference feeling with prejudice

Requirejs ahead of the implementation, advocating reliance on the front,Requirejs in the attempt to let the third-party class library to modify itself to support Requirejs, currently only a few community adoption (currently I use the library Echart, Hightchart and so on can support requirejs2.0).

Seajs deferred execution, respected the nearest dependency, very concerned about the development of code debugging, there are NoCache, debug and other debugging plug-ins. Sea.js not strong push, adopt the way of self-encapsulation to "Haina hundred Rivers", now has the more mature encapsulation strategy.

Usage

//CMDDefinefunction(Require, exports, module) {varA = require ('./a ')) a.dosomething ()//100 lines are omitted here    varb = require ('./b ')//Reliance can be written nearb.dosomething ()// ...})//the default recommended by AMD isdefine (['./a ', './b '),function(A, B) {//dependence must be written right from the starta.dosomething ()//100 lines are omitted hereb.dosomething ()// ...})

Iv. references

AMD Specification Document Https://github.com/amdjs/amdjs-api/wiki/AMD

Amdjs require interface documentation Https://github.com/amdjs/amdjs-api/wiki/require
Interface documentation for AMDJS Https://github.com/amdjs/amdjs-api/wiki
REQUIREJS official Website Interface Document http://www.requirejs.org/docs/api.html module system The value of https://github.com/seajs/seajs/issues/240 front-end modular development https://github.com/seajs/seajs/issues/547 Front-end modular development that point of History Https://github.com/seajs/seajs/issues/588CMD module definition specification https:// GITHUB.COM/SEAJS/SEAJS/ISSUES/242SEAJS API Quick Reference https://github.com/seajs/seajs/issues/266 from CommonJS to Sea.js https:// github.com/seajs/seajs/issues/269

Requirejs and AMD Specification http://javascript.ruanyifeng.com/tool/requirejs.html

COMMONJS Specification Http://javascript.ruanyifeng.com/nodejs/commonjs.htmlJavascript Modular Programming http://www.ruanyifeng.com/blog/ 2012/10/javascript_module.htmljavascript Modular Programming Http://www.ruanyifeng.com/blog/2012/10/asynchronous_module_ Definition.html

What are the differences between AMD and CMD? http://www.zhihu.com/question/20351507

JavaScript Modular Development-COMMONJS specification Http://www.feeldesignstudio.com/2013/09/javascript-module-pattern-commonjs
JavaScript Modular Development-AMD spec HTTP://WWW.FEELDESIGNSTUDIO.COM/2013/09/JAVASCRIPT-MODULE-PATTERN-AMD

Modular Design Http://baike.baidu.com/view/189730.htm
Modular http://baike.baidu.com/view/182267.htm

"Front-end coding" modular programming

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.