当前位置:网站首页>Componentization and modularization
Componentization and modularization
2022-07-25 15:38:00 【Gorgio_ Liu】
Componentization
Why component development
Sometimes the amount of page code is too large , Too much logic or the same functional component is used on many pages , Maintenance is quite complicated , This is the time , Component development is needed to split functions 、 Component encapsulation , To achieve component versatility , Enhance code readability , Maintenance costs can also be greatly reduced .
The advantages of component development
Reduce the coupling of various functions of the system to a great extent , And improve the aggregation within the function . This is important for front-end engineering and reducing code maintenance , There are great benefits , The reduction of coupling , It improves the extensibility of the system , Reduce the complexity of development , Improve development efficiency , Reduce development costs .
The principle of component development
Single mindedness
Configurability
Standardization
reusability
Maintainability
modularization
Why modularity
In the early JavaScript Version has no block level scope 、 There is no class 、 No bag 、 There are no modules , This will bring some problems , Such as reuse 、 rely on 、 Conflict 、 The code is disorganized, etc , With the expansion of the front end , Modularity is very urgent
The benefits of modularity
Avoid variable pollution , name conflict
Improve code reuse rate
Improved maintainability
Facilitate dependency management
Several methods of modularization
Function encapsulation
var myModule = {
var1:1,
var2:2,
fn1:function() {
},
fn2:function() {
}
}
summary : This avoids contamination of variables , Just make sure the module name is unique , At the same time, members in the same module also have relationships
defects : The external can modify the internal members at will , This creates unexpected safety problems
Execute the function expression immediately (IIFE)
var myModule = (function() {
var var1=1;
var var2=2;
function fn1() {
}
function fn2() {
}
return {
fn1:fn1,
fn2:fn2
};
})();
summary : This prevents us from modifying variables outside the module that we have not exposed 、 function
shortcoming : The function is relatively weak , The packaging process increases the workload , Namespace contamination may still occur 、 Closures have costs .
边栏推荐
- Pytorch学习笔记-刘二老师RNN高级篇-代码注释及结果
- Qtime定义(手工废物利用简单好看)
- MySQL transactions and mvcc
- Brain racking CPU context switching
- JVM—类加载器和双亲委派模型
- ICPC2021昆明M-暴力+主席树
- 解决vender-base.66c6fc1c0b393478adf7.js:6 TypeError: Cannot read property ‘validate‘ of undefined问题
- 2016 CCPC network trial c-change root DP good question
- 2019陕西省省赛K-变种Dijstra
- 带你创建你的第一个C#程序(建议收藏)
猜你喜欢

盒子躲避鼠标

Phased summary of the research and development of the "library management system -" borrowing and returning "module

LeetCode - 707 设计链表 (设计)

ML - 自然语言处理 - 关键技术

p4552-差分

使用cpolar建立一个商业网站(如何购买域名)

解决vender-base.66c6fc1c0b393478adf7.js:6 TypeError: Cannot read property ‘validate‘ of undefined问题

ML - natural language processing - Basics

Idea eye care settings

Pytorch学习笔记-Advanced_CNN(Using Inception_Module)实现Mnist数据集分类-(注释及结果)
随机推荐
Idea - click the file code to automatically synchronize with the directory
P4552 differential
哪里有搭建flink cdc抽mysql数的demo?
C # fine sorting knowledge points 9 Set 2 (recommended Collection)
CF365-E - Mishka and Divisors,数论+dp
Delayed loading source code analysis:
Pytorch学习笔记--常用函数总结3
Idea eye care settings
BPSK调制系统MATLAB仿真实现(1)
PAT甲级1153 Decode Registration Card of PAT (25 分)
2019 Shaanxi Provincial race K-variant Dijstra
Phased summary of the research and development of the "library management system -" borrowing and returning "module
MySQL optimization summary II
2021上海市赛-B-排序后dp
Games101 review: 3D transformation
Deadlock gossip
Pat grade a 1153 decode registration card of PAT (25 points)
2019 Zhejiang race c-wrong arrangement, greedy
Cf750f1 thinking DP
Endnote 添加中文GBT7714样式 word中如何引用文献