我想像这样缩短 ES6 中的对象文字:
const loc = this.props.local;
原因是loc.foo();
比打字容易得多this.props.local.foo();
但现在 ESLint 抱怨道:
使用对象解构:prefer-destructuring
我读过eslint.org 上的错误描述 https://eslint.org/docs/rules/prefer-destructuring但我不明白。他们有一个看起来与我的代码非常相似的示例,但他们的代码似乎没问题?
var foo = object.bar;
如何修复错误而不将其设置为忽略.eslintrc
file?
更改您的代码:
const local = this.props.local;
to:
const { local } = this.props;
它们是等价的,你可以调用local.foo()
以同样的方式。除了第二个使用对象解构之外。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)