JavaScript Design Patterns cover

JavaScript Design Patterns

Rating 3.5
Word count
269K words
Chapters
40
ISBN
9787115396860

Tags

Summary

This is a practical book on JavaScript design patterns by front-end engineer Zhang Rongming, divided into six parts and forty chapters, built around "how a newly graduated front-end developer gradually understands and uses design patterns in projects." Part One covers the foundations of object-oriented programming in JavaScript: the many ways to write functions, organizing variables with objects, creating classes, encapsulation, inheritance (class-style inheritance, constructor inheritance, prototype inheritance, parasitic combination inheritance, etc.), and polymorphism, laying the groundwork for understanding patterns later. Parts Two through Four introduce patterns one by one according to the classic categories: creational (simple factory, factory method, abstract factory, builder, prototype, singleton), structural (facade, adapter, proxy, decorator, bridge, composite, flyweight), and behavioral (template method, observer, state, strategy, chain of responsibility, command, visitor, mediator, memento, iterator, interpreter). Part Five is grouped as "technique patterns," including chain pattern, delegation pattern, data access object pattern, throttle pattern, simple template pattern, lazy pattern, participant pattern, and waiter pattern; Part Six covers architectural patterns, involving synchronous modules, asynchronous modules, the Widget pattern, and the implementation and evolution of the three front-end architectural patterns MVC, MVP, and MVVM. Each pattern is generally developed according to the structure "definition—application scenarios—problem—solution—summary and exercises," with examples mostly drawn from common front-end needs such as carousels, input boxes, form validation, news modules, cross-domain images, and pagination. It is suitable as an introductory reader for systematically organizing JavaScript design patterns.

Editor's review

很多讲设计模式的书会把 GoF 的 23 种模式直接搬到 JavaScript 上,读起来像一本语法翻译手册。这本书的不同之处在于:它先把 JavaScript 自身的语言特性讲透——函数是一等公民、对象可以随时增删方法、原型链如何替代类继承——再在这个基础上谈“为什么这种模式在 JS 里会变形”。 内容覆盖面很宽:六大类、近四十种模式,从简单工厂一路排到 MVVM,前端常见的焦点图、表单验证、事件委托、模块化、跨域代理都能在节点中找到对应案例。对于没读过 GoF 原著、也没系统学过架构模式的开发者,这种“先摆场景再给定义”的编排方式更容易建立整体地图。 需要提醒的是:书中示例以 ES5 时代的写法为主,MVC/MVP/MVVM 部分的实现偏教学性质,与今天的框架实践差别较大。把它当作“模式索引 + 概念梳理”来读收获最大,具体代码请结合现代规范自行重构。

Who it's for

A good fit for

  • 已能用 JavaScript 写业务代码、想系统补设计模式的前端开发者
  • 准备面试或技术晋升,需要把模式名称与用途对上号的人
  • 计算机相关专业学生,需要一本案例驱动的辅助教材
  • 从后端或其他语言转前端、希望理解 JS 特色写法的程序员

Not a good fit for

  • 完全没有 JavaScript 基础、连闭包和原型都未接触的纯新手
  • 希望读到 React/Vue 时代现代工程化范式与 TS 类型写法的读者
  • 只想找可直接复制到生产环境的工业级代码的人

Reading tips

  1. 第一篇务必按顺序读完,封装、继承、多态没吃透,后面每种模式都会读得吃力。
  2. 第二至第六篇可按需跳读,建议先挑工作中正遇到的场景(如表单验证看策略、事件绑定看外观/委托)。
  3. 每章读完先自己动手实现一遍示例,再回看作者的实现,比对着读效果好。
  4. 遇到 ES5 写法不必纠结,可顺手用 ES6 class、模块化和现代框架对照改写。
  5. 关注每种模式前面的“定义”和后面的“忆之获”,那是全书信息密度最高的部分。

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 Object-Oriented Programming
  2. Chapter 1 A Flexible Language—JavaScript
  3. Chapter 2 What You Write Is What You See—Object-Oriented Programming
  4. Part Two Creational Design Patterns
  5. Chapter 3 The Magic Magician—Simple Factory Pattern
  6. Chapter 4 Give Me a Business Card—Factory Method Pattern
  7. Chapter 5 All That Appears Is Illusion—Abstract Factory Pattern
  8. Chapter 6 Separation Is Combination—Builder Pattern
  9. Chapter 7 The Soul of the Language—Prototype Pattern
  10. Chapter 8 One Person's Loneliness—Singleton Pattern
  11. Part Three Structural Design Patterns
  12. Chapter 9 Combo Service—Facade Pattern
  13. Chapter 10 The Winding Pipe—Adapter Pattern
  14. Chapter 11 The Cowherd and the Weaver Girl—Proxy Pattern
  15. Chapter 12 House Renovation—Decorator Pattern
  16. Chapter 13 Roads Between Cities—Bridge Pattern
  17. Chapter 14 Value Lunch—Composite Pattern
  18. Chapter 15 City Bus—Flyweight Pattern
  19. Part Four Behavioral Design Patterns
  20. Chapter 16 Drawing a Tiger from a Cat—Template Method Pattern
  21. Chapter 17 Communication Satellite—Observer Pattern
  22. Chapter 18 Super Mario—State Pattern
  23. Chapter 19 The Living Zhuge Liang—Strategy Pattern
  24. Chapter 20 The Orderly Station—Chain of Responsibility Pattern
  25. Chapter 21 Command Pattern
  26. Chapter 22 Ambassador to China—Visitor Pattern
  27. Chapter 23 The Matchmaker—Mediator Pattern
  28. Chapter 24 Keep a Good Record—Memento Pattern
  29. Chapter 25 The Bill Counter—Iterator Pattern
  30. Chapter 26 Language Translation—Interpreter Pattern
  31. Part Five Technique Design Patterns
  32. Chapter 27 Endless—Chain Pattern
  33. Chapter 28 The Future Prophet—Delegation Pattern
  34. Chapter 29 Data Manager—Data Access Object Pattern
  35. Chapter 30 Execution Control—Throttle Pattern
  36. Chapter 31 Card Puzzle—Simple Template Pattern
  37. Chapter 32 Machine Learning—Lazy Pattern
  38. Chapter 33 Foreign Battlefield—Participant Pattern
  39. Chapter 34 The Entrance Ceremony—Waiter Pattern
  40. Part Six Architectural Design Patterns

FAQ

这本书和《JavaScript设计模式与开发实践》是同一本吗?
不是。本书作者是张容铭,2015 年 8 月由人民邮电出版社出版,ISBN 9787115396860;《JavaScript设计模式与开发实践》作者是曾探,同年 5 月出版,ISBN 9787115388889,两本书内容与结构都不同。
零基础能直接读这本书吗?
需要至少能写出基本函数和对象,理解 this、闭包、原型链的初步概念。若完全没接触过,建议先读一本 JavaScript 入门书,否则第一篇就会卡住。
书里的例子现在还能用吗?
示例以 ES5 写法为主,部分 DOM 兼容代码和架构模式实现已经过时。模式思想仍然通用,但代码建议结合 ES6+ 与现行框架自行改写后再使用。
全书有多少章、大概什么体量?
共六篇四十章,约 316 页、26.9 万字,属于中等体量的技术书,正常节奏两到三周可通读一遍。
适合作为培训或课程教材吗?
适合。每章后有小结与问答,结构完整、案例贴近前端实际需求,出版社定位也包含大专院校相关专业师生与培训学校教材。

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