Home >Web Front-end >JS Tutorial >What is JavaScript modularization and its advantages and disadvantages?_Basic knowledge

What is JavaScript modularization and its advantages and disadvantages?_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:23:571189browse

Nowadays, MVC frameworks such as backbone, emberjs, spinejs, and batmanjs are invading. CommonJS, AMD, NodeJS, RequireJS, SeaJS, curljs and other modular JavaScripts are coming. The web front-end has evolved into a big front-end, and the web front-end is developing very fast.

1) Let’s take a look at what is modularity?
Modularization is a method of separating the system into independent functional parts, strictly defining module interfaces, and ensuring transparency between modules. Modules in javascript are common in some C, PHP, and java:

C uses include to include .h files; PHP uses require_once to include .php files
java uses import to import packages
This There is a modular idea in .

2) Advantages and disadvantages of modularity:

a>Advantages:
Maintainability
1. Flexible architecture, separation of focus
2 . Convenient combination and decomposition between modules
3. Convenient debugging and upgrading of single module functions
4. Multi-person collaboration without interfering with each other
Testability
1. Can be divided into unit tests

b>Disadvantages:
Performance loss
1. System layering, the call chain will be very long
2. Inter-module communication, sending messages between modules will consume a lot of performance

3) Modularization is also used in recent projects, using seajs, but when referencing jquery, jquery easyui/or jquery UI components, many jquery plug-ins may be used, so if you implement a very In complex interactions, there will be many dependencies between modules. There will be many modules introduced using the define() method. Is there any good method?

4) Attachment:
Cohesion
Cohesion refers to the internal implementation of the module. It is a natural extension of the concepts of information hiding and localization. It marks a module How closely the internal components are combined with each other. The benefit is also obvious, it is much easier to read when related tasks are grouped. When designing, module cohesion should be improved as much as possible to achieve higher module independence.

Coupling degree
Coupling degree refers to the measure of the degree of association between modules. The degree of coupling depends on the complexity of the interface between modules, the location where the module is entered or called, etc. In contrast to cohesion, loosely coupled systems should be pursued when designing.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn