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

问题描述

在使用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)){
    
    
			...
}

猜你喜欢

转载自blog.csdn.net/weixin_42464106/article/details/126248519