Skip to Content
React学习手册
book

React学习手册

by Alex Banks, Eve Porcello
December 2017
Intermediate to advanced
329 pages
6h 9m
Chinese
China Electric Power Press Ltd.
Content preview from React学习手册
54
3
//
第三次迭代
// first = "fullname"
// remaining.join("." = "first"
// object[first] = {first: "Dan", last: "Deacon" }
//
最终结果
// first = "first"
// remaining.length = 0
// object[first] = "Deacon"
递归是一种非常强大的函数式编程技巧,并且易于实现。在实际开发过程中处理循环
操作时应该尽量使用递归。
合成
函数式编程会将具体的业务逻辑拆分成小型的纯函数,以便能够将精力聚焦于特定任
务。最终,用户将会需要把这些小型函数整合到一起。具体来说,用户可能需要合成
它们,以串联或者并联的方式对它们进行调用,或者将它们合成为一个更大的函数,
直到构造出一个应用程序为止。
对于合成来说,与之有关的实现、模式和技术真可谓五花八门。读者可能比较熟悉的
一种方式就是链式调用。在
JavaScript
中,函数可以使用点符号连接在一起,其作用
是获得上一个函数的返回值。
字符串有一个
replace
方法,
replace
方法返回的模板字符串也包含一个
replace
方法。
因此我们可以在转换一个字符时使用点符号将
replace
方法串联起来实现链式调用。
const template = "hh:mm:ss tt"
const clockTime = template.replace("hh", "03")
.replace("mm", "33")
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.
Start your free trial

You might also like

React快速上手开发

React快速上手开发

Stoyan Stefanov
流畅的Python

流畅的Python

Luciano Ramalho
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普

Publisher Resources

ISBN: 9787519814236