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
68
3
模块设计
模块中完成,有一点偏离最终的实现,但本质是相同的。二者最大的区别
在于,在得到想要的
API
之前,我们会反复写
README
文件,这一点其
实与
TDD
非常相似。不管怎样,
API
优先和
README
驱动设计都比直接
进入实现过程有明显的优势。
3.3.3
 删除代码
对于
CSS
,有一种流行的描述是“只增加、不删除的语言(
append-only
language
)”,言下之意是如果你添加了一段
CSS
代码,就不能删除它了,
因为这样做可能会由于级联的原因无意中破坏程序的设计。
JavaScript
没有使删除代码变得非常困难,但它确实是一种高度动态的语言,并且在
JavaScript
中想要删除代码同时保证不会出现任何问题,仍然是一个挑战。
当然,修改模块的内部实现比更改它的公共
API
更容易,因为其影响仅限
于模块内部。不影响
API
而对模块内部进行的更改,通常从外部是看不出
来的。有一个例外,就是当使用者对我们的接口打猴子补丁(
monkey-patch
1
时,有时能观察到模块的一些内部信息。然而,在这种情况下使用者应该
意识到对模块打猴子补丁的脆弱性,这是他们无法控制的,并且需要自行
承担猴子补丁无法正常使用的风险。
3.1.2
节我们说过,最好的代码就是没有代码,这一条法则在删除代码时
也有意义。我们从没写过的代码是不需要担心删除的。代码越少,需要维
护的代码就越少,尚未发现的潜在
bug
就越少,需要阅读和测试的代码也少,
对移动网络速度要求高的人而言需要传输的代码就越少。
1
 猴子补丁是从外部对组件的公共接口进行有目的的修改,以便添加、删除或更改其功能。当 ...
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