title: ESLint(no-prototype-builtins) author: Gamehu tags:
// eslint-disable-next-line no-prototype-builtins
if (!a.hasOwnProperty(key) || !b.hasOwnProperty(key)) return 0;
no-prototype-builtins - Rules - ESLint - Pluggable JavaScript linter
This rule disallows calling some Object.prototype methods directly on object instances.
Examples of incorrect code for this rule:
/*eslint no-prototype-builtins: "error"*/
var hasBarProperty = foo.hasOwnProperty("bar");
var isPrototypeOfBar = foo.isPrototypeOf(bar);
var barIsEnumerable = foo.propertyIsEnumerable("bar");
Examples of correct code for this rule:
/*eslint no-prototype-builtins: "error"*/
var hasBarProperty = Object.prototype.hasOwnProperty.call(foo, "bar");
var isPrototypeOfBar = Object.prototype.isPrototypeOf.call(foo, bar);
var barIsEnumerable = {}.propertyIsEnumerable.call(foo, "bar");