Functional Programming in JavaScript cover

Functional Programming in JavaScript

No rating yet
Chapters
40
ISBN
9787115462046

Tags

Summary

This book is the Chinese translation of Manning's Functional Programming in JavaScript, teaching how to apply functional programming ideas and techniques to everyday JavaScript code with ECMAScript 6, aiming to trade less mutable state for lower complexity and better reasonability.

The book is divided into three parts. Part 1, "Functional Thinking," lays the groundwork: it begins by asking whether functional programming is truly useful, explains the difference between declarative and imperative programming, analyzes the harms of side effects alongside core pillars such as pure functions, referential transparency, substitutability, and immutable data, and presents the practical advantages of functional programming in task decomposition, stream-based data processing, and asynchronous responses. Part 2, "Functional Basics," moves into the technical core: it first covers higher-order JavaScript, including first-class functions, higher-order functions, closures and scope, and using lenses to locate and modify object graphs; it then discusses function chains under the principle of "light data structures, heavy operations," combining data transformations with map, reduce, and filter, and explores recursive thinking, currying, and function composition; finally, it introduces the concept of functors and uses monads to handle branching cases such as errors and null values. Part 3, "Functional Skills," applies these techniques to real-world problems: writing testable code in a functional style, introducing lazy evaluation and optimization of lazy function chains, discussing functional handling in promises and asynchronous flows, and the integrated use of functional programming in server-side and front-end applications.

The examples draw extensively on functional libraries such as Lodash (or lodash-fp) and Ramda, with comparisons to object-oriented approaches that explain the trade-offs. In the preface and throughout the chapters, the author repeatedly emphasizes that the book is not asking you to abandon object orientation, but to add a composable, easily testable programming tool to the JavaScript developer's toolkit.

Editor's review

很多 JavaScript 开发者第一次接触函数式编程,会被一堆名词挡住:柯里化、函子、Monad……但真正难的不是名词,而是“换一种方式思考代码”。这本书的价值恰在这里——它不把函数式当作教条,而是把它当成解决 JavaScript 具体问题的工具箱。 作者 Luis Atencio 有多年在 Java、PHP 与 JavaScript 平台做全栈开发的经验,讲课时习惯先摆出命令式的“旧写法”,再一步步改写成纯函数加组合的“新写法”,让读者直观看到两者的差别:可测试性提高了多少、状态被藏起来了多少、出错的分支被收拢到哪里。全书以 ECMAScript 6 为语言基线,箭头函数、展开运算符、Promise 都能直接用上,不必在旧语法里绕路。 更难得的是它的实用性。示例围绕 Lodash、Ramda 等真实在用的函数式库展开,惰性求值、Promise 链、测试等章节直接对应工程里会遇到的场景。篇幅只有两百页出头,章节短、节奏快,适合放在工位上边读边改代码。如果你已经会写 JavaScript、想摆脱 if 嵌套和随手可改的共享状态,这本书是很合适的起点。

Who it's for

A good fit for

  • 已掌握 JavaScript 基础语法、想系统补齐函数式编程知识的前端开发者
  • 习惯面向对象写法,希望学会用纯函数与组合降低代码复杂度的工程师
  • 需要在项目中引入 Lodash/fp 或 Ramda、搭建数据流式处理逻辑的技术负责人
  • 准备面试或技术分享,需要讲清柯里化、函数组合与 Monad 的读者

Not a good fit for

  • 完全没有编程基础、尚未掌握函数、闭包与数组方法的初学者
  • 只想找一份 ES6 语法速查表、不愿动手改写示例代码的读者
  • 期待系统讲解 Haskell、OCaml 等纯函数式语言的读者

Reading tips

  1. 按三部分顺序阅读,第一部分的纯函数、副作用、不可变数据概念是后面所有技术的地基,不要跳过。
  2. 每章的示例代码建议亲手敲一遍,并刻意把它改写成你项目里的某段循环或 if 判断。
  3. 读到函子与 Monad 时不必纠结范畴论定义,先抓住“把分支与空值收进容器”这一实用目的。
  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 1 Functional Thinking
  2. Chapter 1 Becoming Functional
  3. 1.1 Is Functional Programming Useful?
  4. 1.2 What Is Functional Programming?
  5. 1.2.1 Functional Programming Is Declarative Programming
  6. 1.2.2 The Problems of Side Effects and Pure Functions
  7. 1.2.3 Referential Transparency and Substitutability
  8. 1.2.4 Storing Immutable Data
  9. 1.3 The Advantages of Functional Programming
  10. 1.3.1 Encouraging the Decomposition of Complex Tasks
  11. 1.3.2 Using Stream Chains to Process Data
  12. 1.3.3 Responsiveness in Complex Asynchronous Applications
  13. 1.4 Summary
  14. Chapter 2 Higher-Order JavaScript
  15. 2.1 Why Use JavaScript?
  16. 2.2 Functional Versus Object-Oriented Programming
  17. 2.2.1 Managing the State of JavaScript Objects
  18. 2.2.2 Treating Objects as Values
  19. 2.2.3 Deep-Freezing Mutable Parts
  20. 2.2.4 Using Lenses to Locate and Modify Object Graphs
  21. 2.3 Functions
  22. 2.3.1 First-Class Functions
  23. 2.3.2 Higher-Order Functions
  24. 2.3.3 Types of Function Calls
  25. 2.3.4 Function Methods
  26. 2.4 Closures and Scope
  27. 2.4.1 Global Scope
  28. 2.4.2 Function Scope
  29. 2.4.3 Pseudo-Block Scope
  30. 2.4.4 Practical Uses of Closures
  31. 2.5 Summary
  32. Part 2 Functional Fundamentals
  33. Chapter 3 Light Data Structures, Heavy Operations
  34. 3.1 Understanding Program Control Flow
  35. 3.2 Chaining Methods
  36. 3.3 Function Chains
  37. 3.3.1 Understanding Lambda Expressions
  38. 3.3.2 Transforming Data with _.map
  39. 3.3.3 Collecting Results with _.reduce
  40. 3.3.4 Removing Unwanted Elements with _.filter

FAQ

这本书和《JavaScript函数式编程》是同一本吗?
中文书名略有差异。Manning 出版、Luis Atencio 所著的 Functional Programming in JavaScript,其中文简体版书名为《JavaScript函数式编程指南》,由欧阳继超、屈鉴铭翻译,人民邮电出版社出版,ISBN 为 9787115462046。购买时请以作者与 ISBN 核对,避免与其他同名书混淆。
读这本书需要什么基础?
需要能读写基本的 JavaScript:函数声明、回调、数组方法、闭包与 this 的大致含义。书中以 ECMAScript 6 为基础,会用到箭头函数和 Promise;若对 ES6 新语法完全不熟悉,建议先补一补再读,否则示例会显得吃力。
书中用哪些函数式库?
示例主要借助 Lodash(含 lodash-fp 风格)与 Ramda 等 JavaScript 函数式库,用来演示柯里化、map/reduce/filter 链式组合与函数组合等操作。作者会对照原生写法和库写法,说明各自的可读性与性能取舍。
这本书讲范畴论吗?
不讲。书中涉及函子、Monad 等概念时,落点在用它们封装错误、空值、异步等分支场景,帮助写出可组合的代码,而不是推导数学定义。想深入范畴论的读者需要另外找专门的理论书。
这本书适合当作团队共读材料吗?
比较适合。全书三部分结构清晰、单章篇幅短,便于按周分配;每章示例都能直接对应到业务代码中的循环、条件分支与异步回调,共读后可以组织一次小范围重构练习来巩固。

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