当前位置:网站首页>Do not access Object.prototype method ‘hasOwnProperty‘ from target object....

Do not access Object.prototype method ‘hasOwnProperty‘ from target object....

2022-08-10 13:51:00 禾木白

问题描述

在使用hasOwnProperty()方法时报错:
Do not access Object.prototype method ‘hasOwnProperty’ from target object.eslint(no-prototype-builtins)
在这里插入图片描述

不要访问目标对象的原型方法“hasOwnProperty”

解决方案:

//错误的
if (obj.hasOwnProperty(key)){
    
           ...
}
//正确的
if(obj.prototype.hasOwnProperty.call(key)){
    
			...
}
原网站

版权声明
本文为[禾木白]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_42464106/article/details/126248519