对不起,我知道这真的是一个愚蠢的问题,但是我在谷歌上搜索了几轮后也找不到答案。代码如下:
let x = 0
// After some calculation I know the obj should be:
const obj = {'x': 1 }
// Then how to destructuring assigment at this line
{ x } = obj // this is incorrect
// But if I use: x = obj.x, ESLint warns me: [eslint] Use object destructuring. (prefer-destructuring)
console.log(x);
所以我的问题是在定义了x之后如何使用解构赋值。
发布于 2018-07-13 11:15:43
初始化和析构应该在同一行发生。如果你想设置一个初始值,为什么不使用default value赋值。
let { x = 0 } = obj
https://stackoverflow.com/questions/51317093
复制相似问题