JS 在使用hasOwnProperty()函数时报错

在使用hasOwnProperty()方法判断对象是否具有某种属性时eslint报下列错误:
Do not access Object.prototype method 'hasOwnProperty' from target object.eslintno-prototype-builtins
ESLINT修改了规则,禁止state.hasOwnProperty(key) 这样判断
修改规则前是这样判断:

修改规则后是这样判断:

所以修改代码为:


参考资料:
https://zhuanlan.zhihu.com/p/118126825
https://host.zzidc.com/wljc/1297.html





原文地址:https://www.cnblogs.com/baiyifengyun/p/13584574.html