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学习手册
JavaScript
新特性
25
sound,
powderYell() {
let yell = this.sound.toUpperCase()
console.log(`${yell} ${yell} ${yell}!!!`)
},
speed(mph) {
this.speed = mph
console.log('speed:', mph)
}
}
对象语义增强允许我们将全局变量变成对象,并且因为省去了不必要的关键字
function
,从而减少了代码的输入工作。
扩展运算符
扩展运算符是通过三个点号来完成多种工作任务的。首先,扩展运算符允许用户联合
数组中的内容。比如我们有两个数组,可以通过将二者合二为一的方式构造第三个数
组:
var peaks = ["Tallac", "Ralston", "Rose"]
var canyons = ["Ward", "Blackwood"]
var tahoe = [...peaks, ...canyons]
console.log(tahoe.join(', ')) // Tallac, Ralston, Rose, Ward, Blackwood
数组
peaks
canyons
中的所有元素都被移动到名为
tahoe
新数组中了。
让我们来看看扩展运算符是如何帮助用户解决问题的。还是以上面示例中的
peaks
组为例,假设我们希望获取该数组中的最后一个元素。可以使用
Array.reverse
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