1
0
mirror of https://github.com/ruanyf/es6tutorial.git synced 2025-05-24 18:32:22 +00:00

docs(destructuring): 补全报错信息

这样直接看代码的话,更能直观了解到要先声明 y 才能使用它,而不是在声明 y 前就使用它。
This commit is contained in:
zhangbao 2018-01-01 18:23:16 +08:00 committed by GitHub
parent 95caa944a3
commit 083c99e838
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -169,10 +169,10 @@ if ([1][0] === undefined) {
let [x = 1, y = x] = []; // x=1; y=1
let [x = 1, y = x] = [2]; // x=2; y=2
let [x = 1, y = x] = [1, 2]; // x=1; y=2
let [x = y, y = 1] = []; // ReferenceError
let [x = y, y = 1] = []; // ReferenceError: y is not defined
```
上面最后一个表达式之所以会报错,是因为`x`到默认值`y`时,`y`还没有声明。
上面最后一个表达式之所以会报错,是因为`x``y`做默认值时,`y`还没有声明。
## 对象的解构赋值