数组解构
var names = ["abc", "cba", undefined, "nba", "mba"]
-
基本使用
var [name1, name2, name3] = names
-
顺序问题: 严格的顺序
var [name1, , name3] = names
-
解构出数组
var [name1, name2, ...newNames] = names
-
解构的默认值
var [name1, name2, name3 = "default"] = names
对象解构
var obj = { name: "why", age: 18, height: 1.88 }
-
基本使用
var { name, age, height } = obj
-
顺序问题
var { height, name, age } = obj
-
对变量进行重命名
var { height: wHeight, name: wName, age: wAge } = obj
-
默认值
var { height: wHeight, name: wName, age: wAge, address: wAddress = "中国"} = obj
-
对象的剩余内容
var { name,age,...newObj} = obj