Sometimes, we want to fix Object.hasOwnProperty() yielding the ESLint ‘no-prototype-builtins’ error with JavaScript.
In this article, we’ll look at how to fix Object.hasOwnProperty() yielding the ESLint ‘no-prototype-builtins’ error with JavaScript.
How to fix Object.hasOwnProperty() yielding the ESLint ‘no-prototype-builtins’ error with JavaScript?
To fix Object.hasOwnProperty() yielding the ESLint ‘no-prototype-builtins’ error with JavaScript, we can use Object.prototype.hasOwnProperty.call instead of the hasOwnProperty of an object.
For instance, we write
Object.prototype.hasOwnProperty.call(obj, prop);
to call hasOwnProperty on obj with obj as the value of this.
We pass in prop as the 2nd argument to check if prop exists in obj.
Conclusion
To fix Object.hasOwnProperty() yielding the ESLint ‘no-prototype-builtins’ error with JavaScript, we can use Object.prototype.hasOwnProperty.call instead of the hasOwnProperty of an object.