Skip to content

Latest commit

 

History

History
23 lines (15 loc) · 615 Bytes

prefer-object-has-own.md

File metadata and controls

23 lines (15 loc) · 615 Bytes

Prefer use of Object.hasOwn over Object.prototype.hasOwnPrototype (prefer-object-has-own)

When Object.prototype.hasOwnPrototype.call is used, this rule requires using the Object.hasOwn instead. Object.hasOwn is a syntactic sugar and makes the code cleaner.

Rule Details

Examples of incorrect code for this rule:

/*eslint prefer-object-has-own: "error"*/
Object.prototype.hasOwnProperty.call(obj, "a");

let a = Object.prototype.hasOwnProperty;
a.call(obj, "a");

Examples of correct code for this rule:

/*eslint prefer-object-has-own: "error"*/

Object.hasOwn(obj, "a");