今天在跑项目过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')) {
}

快来试试吧

相关文章:

  • 2022-12-23
  • 2021-08-01
  • 2021-09-25
  • 2021-08-23
  • 2021-06-28
  • 2021-07-29
  • 2022-12-23
  • 2021-09-24
猜你喜欢
  • 2021-06-26
  • 2022-01-06
  • 2022-12-23
  • 2022-12-23
  • 2022-02-11
  • 2022-01-24
相关资源
相似解决方案