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
6.3
 作为黑盒的接口
145
息,使用这个文件,包管理工具就可以每次都安装相同的版本,使我们能
快速迭代和更新安装包,同时保证代码的安全。
始终安装相同版本的依赖项以及嵌套依赖项(依赖的依赖),能够促使我们
在开发环境中获得与生产环境相似的使用体验。这有助于我们在本地环境
迅速复现生产环境中的
bug
,同时降低代码在开发过程中正常运行而在预
发布环境中失败的概率。
6.3
 作为黑盒的接口
与前面章节所提到的类似,我们应该像对待第三方库和模块一样对待自己
的组件。当然,我们可以更改自己的代码,这比修改第三方代码要快得多(在
某些情况下)。然而,当我们将所有组件和接口(包括自己的
HTTP API
视为与我们无关时,就可以专注于接口的调用和测试,不去管底层的实现。
改进接口的一种途径是撰写一份详细的文档,描述接口接触点期望的输入,
以及它是如何影响在每种情况下的输出的。在写文档的过程中,我们会发
现接口设计的局限性,可能因此而决定对接口做一些改动。接口的使用者
都喜欢详尽的文档,因为这意味着他们不需要花费太多时间来理解接口是
如何被使用的,以及接口是否能满足他们的需求。
避免对依赖项区别对待有助于我们编写单元测试。在单元测试中,我们可
以模拟未经测试的依赖项,无论它们是由内部人员开发的还是由第三方开
发的。在编写测试用例时,我们总是假设第三方模块已经经过了充分的测试,
因此在我们的测试用例中不必再去测试它们。对于自己的模块,这个假设
也同样适用,而它们正是我们在测试的模块的依赖。
对于安全关注点,上述推理也是可行的,例如对输入的处理。无论开发什 ...
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