Maintainable JavaScript cover

Maintainable JavaScript

Rating 4.0
Word count
400 words
Chapters
25
ISBN
9787115310088

Tags

Summary

Maintainable JavaScript is one of the representative works of Nicholas C. Zakas, author of Professional JavaScript for Web Developers. The original was published by O'Reilly Media in 2012, and the Chinese edition, translated by Li Jing, Guo Kai, and Zhang Sanji of the Taobao UED team, was released by Posts & Telecom Press in April 2013. The author spent more than five years as chief front-end engineer at Yahoo!, moving from lone-wolf hacker-style programming to large-team collaboration, and this book distills that experience: in a multi-person front-end project, code readability often matters more than clever technique, and consistency more than personal preference. The book has three parts. Part One, "Style Guidelines," starts from basic formatting and discusses indentation, statement endings, line length, line breaks, blank lines, naming, and literal syntax, then covers when to comment and documentation comments, statements and expressions (brace alignment, switch, with, for and for-in), variable and function declarations, strict mode, equality operators, and eval. Part Two, "Programming Practices," moves to architecture: loose coupling of the UI layer (keeping CSS out of JavaScript and HTML out of scripts), avoiding globals (single global object, namespaces, modules, AMD), the two principles of event handling, avoiding comparison with null, separating configuration data from code, throwing errors proactively, not modifying objects you don't own, and feature detection instead of browser detection. Part Three, "Automation," centers on builds: file and directory structure, Ant build scripts, validation, concatenation and "baking," minification and gzip, documentation generation, and automated testing (YUI Test, Selenium, PhantomJS, JsTestDriver, and others), finally showing how to assemble the scattered pieces into development, integration, and release builds and hook them to a continuous integration server. The Chinese edition runs about 226 pages; dense with examples and clearly itemized, it reads more like a style manual and engineering practice guide you can put to work directly.

Editor's review

很多 JavaScript 学习者能写出跑得起来的代码,却写不出别人愿意接手的代码。本书解决的正是这件事:它不教你新语法,而是教你如何在团队中把代码写“整齐”。 作者扎卡斯是《JavaScript高级程序设计》的作者,在 Yahoo! 带过大型前端项目,书中每一条规则几乎都来自真实项目的教训。它的结构非常务实:编程风格部分细到缩进几级、逗号放哪、什么时候该写注释,读起来像一份逐条解释理由的团队规范;编程实践部分则提高了层次,涉及 UI 松耦合、全局变量治理、配置数据外置、自定义错误、不改他人对象、特性检测等至今仍被反复引用的原则;自动化部分手把手讲代码校验、合并、压缩、文档与自动化测试,并演示如何拼装成一套可运行的构建流程。 需要说明的是,自动化部分的具体工具(Ant、YUI Compressor、YUI Test、PhantomJS 等)在今天多已被 ESLint、打包器和现代测试框架取代,读这部分时应关注“为什么需要这一步”,而非照搬当年工具。中文版由淘宝UED团队翻译,术语准确、行文顺畅。对于想从“能写”跨到“能协作、可交付”的前端开发者,这仍是一本值得放在手边翻查的方法论书籍。

Who it's for

A good fit for

  • 已有一定 JavaScript 基础、开始参与多人协作项目的前端开发者
  • 需要为团队制定或更新编码规范、代码评审清单的前端负责人
  • 刚进入职场、想快速摸清工程化与代码质量门槛的初级工程师
  • 带实习生或做技术培训、需要一份讲得清“为什么”的教材的讲师

Not a good fit for

  • 完全零基础、尚未写过完整 JavaScript 程序的入门读者
  • 主要想学框架用法或最新语法特性的读者,本书几乎不涉及这类内容
  • 期待拿到可直接套用的现代构建脚本的读者,书中工具链已明显过时

Reading tips

  1. 把本书当规范手册用:先通读第一部分,再在评审或重构时按条目回查,不必一次读完。
  2. 读编程实践部分时,打开自己项目里最乱的那个文件,边读边做对照修改,收效最直接。
  3. 自动化部分重点理解流程与目的,工具选型换成 ESLint、Prettier、打包器和现行测试框架即可。
  4. 团队共读时建议每周过一章,把书中条目剪裁成本团队的编码规范并落到评审清单里。

About the publisher

Posts & Telecom Press China · Founded in 1953

Posts & Telecom Press is known for its strengths in science and technology, computing, and information and communications titles, and has extended its publishing into photography, art, software learning, and inspirational growth, giving it a fairly diverse range. Its catalog includes computing and communications works such as Refactoring and Patterns (Revised Edition) and Huawei Switch Learning Guide (Second Edition), alongside bilingual collector's editions such as The Little Prince (Chinese-English-French illustrated collector's edition), The Great Gatsby, and Three Days to See. Beijing Ten Years: 1980-1990 and Ghost Blade: WLOP Personal Illustration Collection reflect its presence in photography and art. Its authors include Antoine de Saint-Exupéry, Helen Keller, Joshua Kerievsky, Wang Da, Zhang Zhaozeng, and WLOP.

Contents

  1. Part One Style Guidelines
  2. Chapter 1 Basic Formatting
  3. Chapter 2 Comments
  4. Chapter 3 Statements and Expressions
  5. Chapter 4 Variables, Functions, and Operators
  6. Part Two Programming Practices
  7. Chapter 5 Loose Coupling of the UI Layer
  8. Chapter 6 Avoiding Global Variables
  9. Chapter 7 Event Handling
  10. Chapter 8 Avoiding "Null Comparisons"
  11. Chapter 9 Separating Configuration Data from Code
  12. Chapter 10 Throwing Custom Errors
  13. Chapter 11 Don't Modify Objects You Don't Own
  14. Chapter 12 Browser Detection
  15. Part Three Automation
  16. Chapter 13 File and Directory Structure
  17. Chapter 14 Ant
  18. Chapter 15 Validation
  19. Chapter 16 File Concatenation and Processing
  20. Chapter 17 File Minification and Compression
  21. Chapter 18 Documentation
  22. Chapter 19 Automated Testing
  23. Chapter 20 Putting It All Together
  24. Appendix A JavaScript Style Guide
  25. Appendix B JavaScript Tools

FAQ

这本书和《JavaScript高级程序设计》是同一作者吗?
是。两者作者都是尼古拉斯·C. 扎卡斯(Nicholas C. Zakas)。《JavaScript高级程序设计》讲语言本身,本书讲的则是团队协作中如何组织、规范和自动化 JavaScript 代码,定位完全不同,可以互补阅读。
2013年出版的书,现在读还不过时吗?
前半部分关于风格、注释、松耦合、全局变量、错误处理、特性检测的原则基本不过时;第三部分的 Ant、YUI Compressor、PhantomJS 等具体工具已基本退出主流,建议把这一部分当作“为什么要做自动化”的入门思路来读。
中文版是谁翻译的,质量如何?
中文版由李晶、郭凯、张散集翻译,属淘宝UED团队组织,是国内较早有前端团队参与译校的技术书之一,术语处理较为一致,翻译质量常被读者提及为优点。
需要先精通 JavaScript 再读吗?
不需要精通,但要能独立写出包含函数、对象、事件处理的完整脚本。书中大量示例涉及回调、闭包与模块模式,完全没有基础会读得吃力,建议先完成一门入门课再读。
书的篇幅大吗,多久能读完?
中文版约226页,正文20章加两个附录。通读大约需要一周到两周的碎片时间;如果只读第一、二部分(前12章),三四个晚上即可完成,这也是多数读者建议的读法。

Comments

Find this book

This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.

Top rated in the same category