Disallow use of Object.prototype.hasOwnProperty.call()
and prefer use of Object.hasOwn()
Some problems reported by this rule are automatically fixable by the --fix
command line option
It is very common to write code like:
This is a common practice because methods on Object.prototype
can sometimes be unavailable or redefined (see the no-prototype-builtins rule).
Introduced in ES2022, Object.hasOwn()
is a shorter alternative to Object.prototype.hasOwnProperty.call()
:
Examples of incorrect code for this rule:
Examples of correct code for this rule:
This rule should not be used unless ES2022 is supported in your codebase.
This rule was introduced in ESLint v8.5.0.
© OpenJS Foundation and other contributors
Licensed under the MIT License.
https://eslint.org/docs/latest/rules/prefer-object-has-own