Functional Programming in JavaScript
Tags
Summary
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
Who it's for
A good fit for
- 已掌握 JavaScript 基础语法、想系统补齐函数式编程知识的前端开发者
- 习惯面向对象写法,希望学会用纯函数与组合降低代码复杂度的工程师
- 需要在项目中引入 Lodash/fp 或 Ramda、搭建数据流式处理逻辑的技术负责人
- 准备面试或技术分享,需要讲清柯里化、函数组合与 Monad 的读者
Not a good fit for
- 完全没有编程基础、尚未掌握函数、闭包与数组方法的初学者
- 只想找一份 ES6 语法速查表、不愿动手改写示例代码的读者
- 期待系统讲解 Haskell、OCaml 等纯函数式语言的读者
Reading tips
- 按三部分顺序阅读,第一部分的纯函数、副作用、不可变数据概念是后面所有技术的地基,不要跳过。
- 每章的示例代码建议亲手敲一遍,并刻意把它改写成你项目里的某段循环或 if 判断。
- 读到函子与 Monad 时不必纠结范畴论定义,先抓住“把分支与空值收进容器”这一实用目的。
- 读完后挑一个模块做小型重构试验,配合单元测试验证行为不变,体会函数式带来的可测试性。
About the publisher
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
- Part 1 Functional Thinking
- Chapter 1 Becoming Functional
- 1.1 Is Functional Programming Useful?
- 1.2 What Is Functional Programming?
- 1.2.1 Functional Programming Is Declarative Programming
- 1.2.2 The Problems of Side Effects and Pure Functions
- 1.2.3 Referential Transparency and Substitutability
- 1.2.4 Storing Immutable Data
- 1.3 The Advantages of Functional Programming
- 1.3.1 Encouraging the Decomposition of Complex Tasks
- 1.3.2 Using Stream Chains to Process Data
- 1.3.3 Responsiveness in Complex Asynchronous Applications
- 1.4 Summary
- Chapter 2 Higher-Order JavaScript
- 2.1 Why Use JavaScript?
- 2.2 Functional Versus Object-Oriented Programming
- 2.2.1 Managing the State of JavaScript Objects
- 2.2.2 Treating Objects as Values
- 2.2.3 Deep-Freezing Mutable Parts
- 2.2.4 Using Lenses to Locate and Modify Object Graphs
- 2.3 Functions
- 2.3.1 First-Class Functions
- 2.3.2 Higher-Order Functions
- 2.3.3 Types of Function Calls
- 2.3.4 Function Methods
- 2.4 Closures and Scope
- 2.4.1 Global Scope
- 2.4.2 Function Scope
- 2.4.3 Pseudo-Block Scope
- 2.4.4 Practical Uses of Closures
- 2.5 Summary
- Part 2 Functional Fundamentals
- Chapter 3 Light Data Structures, Heavy Operations
- 3.1 Understanding Program Control Flow
- 3.2 Chaining Methods
- 3.3 Function Chains
- 3.3.1 Understanding Lambda Expressions
- 3.3.2 Transforming Data with _.map
- 3.3.3 Collecting Results with _.reduce
- 3.3.4 Removing Unwanted Elements with _.filter
FAQ
这本书和《JavaScript函数式编程》是同一本吗?
读这本书需要什么基础?
书中用哪些函数式库?
这本书讲范畴论吗?
这本书适合当作团队共读材料吗?
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.