Object.hasOwn(…)
is more accessible than Object.prototype.hasOwnProperty.call(…)
.
This rule is fixable.
const hasProperty = Object.prototype.hasOwnProperty.call(object, property);
const hasProperty = {}.hasOwnProperty.call(object, property);
const hasProperty = lodash.has(object, property);
const hasProperty = Object.hasOwn(object, property);
Type: object
Type: string[]
You can also check custom functions that indicating the object has the specified property as its own property.
_.has()
, lodash.has()
, and underscore.has()
are checked by default.
Example:
{
'unicorn/prefer-object-has-own': [
'error',
{
functions: [
'has',
'utils.has',
]
}
]
}
// eslint unicorn/prefer-object-has-own: ["error", {"functions": ["utils.has"]}]
const hasProperty = utils.has(object, property); // Fails