LoginSignup
0
0

More than 1 year has passed since last update.

Do not access Object.prototype method 'hasOwnProperty' from target object no-prototype-builtinsの対処法

Posted at

はじめに

eslint実施時に以下のエラーが出たため、その時の対応をまとめました。

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

問題のコード

const hasProperty = entry.hasOwnProperty('Key');
if (hasProperty) {
	// 処理
}

改善したコード

以下のようにObject.prototypeを使うことでエラーが出なくなりました。

const hasProperty = Object.prototype.hasOwnProperty.call(entry, 'Key');
if (hasProperty) {
	// 処理
}

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0