Do not access Object.prototype method 'hasOwnProperty' from target object.eslintno-prototype-builtins

今天在跑项目过lint时报错了,如下图
Do not access Object.prototype method 'hasOwnProperty' from target object.eslintno-prototype-builtins
查了下大概意思是不要使用对象原型上的方法,因为原型上的方法可能被重写了。
那重点来了如何修复呢?

// bad
if (obj.hasOwnProperty('name')) {
}

// good
if (Object.prototype.hasOwnProperty.call(obj, 'name')) {
}

快来试试吧