为什么eslint airBnB为For ... In循环抛出错误?

时间:2017-03-29 00:38:51

标签: javascript object eslint airbnb

我通常遵循eslint AirBnB配置,我注意到我在使用For ... In循环时遇到了错误?为什么会这样?

我已经读了一下Here,但我想要更详细的解释或示例。

const data = {
 color  : 'blue',
 movies : 'action',
 hobby  : 'football',
};

for (let prop in data) {
  console.log(`prop: ${prop} and value is ${data[prop]}`);
}
//Throws Guarding for in, should be wrapped in an if statement to    
//filter unwated properties from the prototype. 

Object.keys(data).forEach((element) => {
  console.log(`prop: ${element} and value is ${data[element]}`);
});
//This is Okay

0 个答案:

没有答案