Skip to Content
精通模块化JavaScript
book

精通模块化JavaScript

by Nicolás Bevacqua
April 2020
Intermediate to advanced
177 pages
1h 45m
Chinese
Publishing House of Electronics Industry
Content preview from 精通模块化JavaScript
71
4
内部构造
到目前为止,我们已经从宏观角度讨论了模块化设计和
API
设计的关注点,
但还没有涉及深层的实现细节。与前面的章节不同,本章的主要内容是一
些建议和具体措施,可以利用它们来改善组件的实现质量。我们将会讨论
复杂性、降低复杂性的方法、状态的风险以及如何更好地利用数据结构。
4.1
 内部复杂性
我们所写的每一段代码都是内部复杂性的源头,都有可能成为整个代码库
的一大痛点。也就是说,大多数代码与整个代码库比起来是相对无害的,
而试图证明我们的代码不具有复杂性,这种做法本身无疑会增加复杂性,
而且不会带来任何好处。问题是,如何在小问题发展成为严重威胁项目可
维护性的大问题之前识别它们?
有意识地跟踪一段时间内我们没有做过修改或者与之交互的代码,并确认
它们是否足够简单易懂,这种方法可以帮助我们决定是否应该对代码进行
重构。也许我们可以设置一个规则,即团队成员应该留意代码中复杂且不
72
4
内部构造
易理解的部分,并在修改与受影响的代码相同的功能区域时修复它们。如
果你经常在负责某个代码库的整个团队中系统地跟踪代码复杂性,那么在
对抗复杂性的斗争中可以看到许多微小但是不断积累的成效。
4.1.1
 包含嵌套的复杂性
JavaScript
中,深度嵌套是复杂性最明显的标志之一。要理解某个嵌套
层级的代码, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

数据驱动力:企业数据分析实战

数据驱动力:企业数据分析实战

Carl Anderson
基于Python的智能文本分析

基于Python的智能文本分析

Benjamin Bengfort, Rebecca Bilbro, Tony Ojeda
Lua游戏AI开发指南

Lua游戏AI开发指南

Posts & Telecom Press, David Young

Publisher Resources

ISBN: 9787121387074