如何交换两个数?
在ES6之前要多声明一个变量来暂存
a=1 b=2 t=a a=b b=t
而在ES6中可以这样[a, b] = [b, a]
[a, b, ...rest] = [1, 2, 3, 4, 5]
所以...rest就是后面的3,4,5在ES6之前
var frank = {name: 'frank', age: 18}var name = frank.namevar age = frank.age
在ES6之后可以这样赋值
var {name, age} = frank
[a= 3, b=1] = [1]
[a, b] = f()
var f = function () { return [1, 2] }var [a, b] = f()
[a, , b] = f()
var f = function () { return [1, 2, 3] }var [a, , b] = f()
作者:徐金俊
链接:https://www.jianshu.com/p/68fc2368a9d1