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
154
6
开发的方法论与哲学
式来定位文本光标。这与我们严格的
CSP
规则不一致,但由于我们的开发
环境在
CSP
规则方面的要求比在生产环境中更宽松,因此我们根本无法意
识到这一点。
应该尽可能努力地将这些差异控制到最小,如果不这样做,生产环境中可
能会冒出很多
bug
,而用户最终可能会向我们报告它们。仅仅意识到这样
的差异是不够的,因为要在脑子里记住这些逻辑门既不实际也不有效。最
好的办法是无论何时实施更改,都在脑子里思考这个问题 :如果代码是在
生产环境中运行的,那么这些变更将会有什么不同?
适当地做集成测试可能会捕获许多这类错误,但情况并非总是如此。
6.7
 抽象问题
匆忙做出来的抽象会导致灾难。反过来,如果没有识别并抽象出主要的复
杂性来源,代价也会非常高昂。当我们直接使用复杂的接口却并不一定用
到了接口提供的所有高级配置选项时,我们就错过了一个可以利用的强大
抽象。另一种方法是在该复杂接口的前面创建一个中间层,然后让用户通
过该层间接使用接口。
这个中间层将负责调用该复杂抽象本身,它提供了一个更简单的接口,配
置选项更少,并且重要用例的易用性更高。通常,复杂或遗留的接口都会
要求我们提供可以从函数调用传递的其他参数派生的数据。例如,我们可
能会被问到分别有多少成年人和孩子以及总共有多少人想要预订航班,尽
管后者可以从前者派生出来。还有一些其他的例子,比如期望字段采用特
定的字符串格式(例如可以从原生
JavaScript
日期派生的日期字符串),使
6.7
 抽象问题
155
用与实现相关但与使用者无关的命名法,或者缺少合理的默认设置 ...
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