简体   繁体   English

如何在JavaScript中解析eslinter的无限制语法?

[英]How do I resolve the no-restricted-syntax from eslinter in JavaScript ?

I am using ESLint in my project and am using the airbnb style guide. 我在我的项目中使用ESLint并使用了airbnb风格指南。 The following piece of code in my program is giving me a linting issue. 我程序中的以下代码给了我一个linting问题。 I am working on ES6. 我正在研究ES6。 It's telling me to avoid using for-in here. 它告诉我要避免在这里使用for-in。 What would be a better alternative as per ES6 standards ? 根据ES6标准,什么是更好的选择?

function solveRole (i18nData) {
  entries = {};

    for (const property in i18nData) {
    entries[property] = i18nData[property];
  }
}

There's no need to iterate over the keys using either a for-in loop or Object.keys(...).forEach as all you are doing is assigning all properties of one object to another. 无需使用for-in循环或Object.keys(...).forEach迭代键,因为您所做的只是将一个对象的所有属性分配给另一个对象。

Try this: 试试这个:

entries = Object.assign({}, i18nData)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM