所以基本上我有这段代码:
Array.prototype.inState = function (needle, haystack) {
let index = this.findIndex(value => value[needle] === haystack);
return index === -1;
};
它的工作原理足以检查给定的针头是否处于反应状态。但是 ESlint 一直在说:
Array prototype is read only, properties should not be added no-extend-native
所以我的问题是:我的代码有什么问题?
原文由 AH.Pooladvand 发布,翻译遵循 CC BY-SA 4.0 许可协议
来自 EsLint 文档:
简而言之,
Array.prototype.inState
将扩展array.prototype
因此无论何时你想使用一个数组,instate 函数也将被添加到该数组。因此,在您的情况下,此示例将应用于数组。
解决方法
您可以添加此行以忽略警告。
参考: https ://eslint.org/docs/rules/no-extend-native