我想像这样缩短 ES6 中的对象文字:
const loc = this.props.local;
原因是 loc.foo();
比 this.props.local.foo();
更容易输入
但是现在 ESLint 提示:
Use object destructuring: prefer-destructuring
我读过 error description on eslint.org但我不明白。他们有一个看起来与我的代码非常相似的示例,但他们的代码似乎没问题?
var foo = object.bar;
如何修复错误而不在 .eslintrc
文件中将其设置为忽略?
最佳答案
更改您的代码:
const local = this.props.local;
到:
const { local } = this.props;
它们是等价的,你可以用同样的方式调用local.foo()
。除了第二次使用对象解构。
关于javascript - 如何修复 Eslint 错误 "prefer-destructuring"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47395070/