1
0
mirror of https://github.com/ruanyf/es6tutorial.git synced 2025-05-25 03:02:21 +00:00

update object.md

let {x}=null就会报错了
let {...x}=null才会体现解构中...运算符引起报错
其实任何对null和undefined的解构都会报错
This commit is contained in:
bigbird231 2019-04-08 18:33:06 +08:00 committed by GitHub
parent 6c1aaf1b3f
commit 0c61cc13ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -473,8 +473,8 @@ z // { a: 3, b: 4 }
由于解构赋值要求等号右边是一个对象,所以如果等号右边是`undefined``null`,就会报错,因为它们无法转为对象。 由于解构赋值要求等号右边是一个对象,所以如果等号右边是`undefined``null`,就会报错,因为它们无法转为对象。
```javascript ```javascript
let { x, y, ...z } = null; // 运行时错误 let { ...z } = null; // 运行时错误
let { x, y, ...z } = undefined; // 运行时错误 let { ...z } = undefined; // 运行时错误
``` ```
解构赋值必须是最后一个参数,否则会报错。 解构赋值必须是最后一个参数,否则会报错。