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
47
3
模块设计
多站在
API
驱动设计和文档驱动设计的角度进行思考,就能写出更多具有
可用性的模块。你可能会说内部构造没那么重要,“只要接口能承受,可以
把任何想要的东西混在一起!”然而,有一个可用的接口只是问题的一个
方面,它对保持应用程序的可维护性几乎没有什么用。设计合理的模块内
部结构有助于保持代码的可读性和意图的清晰性。本章将讨论在编写具有
可扩展性却不超出当前需求范围太多的模块时需要考虑些什么问题。我们
将更深入地讨论
CRUST
原则,最后还会阐述当模块随着时间的推移变得
越来越臃肿且复杂时该如何进行修剪。
3.1
 构建模块
要实现整洁的(
clean
)模块设计,关键在于要实现一组小且作用唯一的函数。
为唯一用途而编写的函数,即使其所属的模块增长到
500
行代码,仍然具
有良好的可扩展性,因为它们在所属模块中并未引入多少组织结构上的复
杂性。小函数发挥的作用不一定逊于大函数,而且前者在进行组合时更有
优势。
48
3
模块设计
假设我们不是用
100
行代码实现一个函数,而是将其分解为
3
个或更多更
小的函数,那么日后或许可以在模块的其他地方重用这些小函数,这些函
数还可能成为其公共接口的有效补充。
本章的目的是,讨论如果要在模块级别降低复杂性,在设计代码时需要考
虑哪些因素。虽然本章将要讨论的大部分内容与我们编写函数的方式有关, ...
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