This is a common practices because methods on Object.prototype can sometimes be unavailable or redefined.
Object.create(null)
Object.create(null) will create an object that does not inherit from Object.prototype, making those methods inaccessible.
Object.create(null).hasOwnProperty("foo")// Uncaught TypeError: Object.create(...).hasOwnProperty is not a function
Redefining hasOwnProperty
If you do not directly own every property defined of an object, you can’t be 100% certain that calling .hasOwnProperty() is calling the built-in method:
let object = { hasOwnProperty() { throw new Error("gotcha!") }}object.hasOwnProperty("foo")// Uncaught Error: gotcha!
ESLint no-prototype-builtins
ESLint has a built-in rule for banning use of prototype builtins like hasOwnProperty.
From the ESLint documentation for no-prototype-builtins:
The MDN documentation for Object.prototype.hasOwnProperty includes advice not to use it off of the prototype chain directly:
JavaScript does not protect the property name hasOwnProperty; thus, if the possibility exists that an object might have a property with this name, it is necessary to use an external hasOwnProperty to get correct results […]
Proposal
This proposal adds a Object.hasOwn(object, property) method with the same behavior as calling hasOwnProperty.call(object, property)
Object.hasOwnProperty(property) already exists today because Object itself inherits from Object.prototype so defining a new method with a different signature would be a breaking change.
JavaScript also supports Maps, which are often a more suitable data structure than regular objects. So in code that you have full control over, you might be using maps instead of objects. However, as a developer, you do not always get to choose the representation. Sometimes the data you’re operating on comes from an external API or from some library function that gives you an object instead of a map.
Why not place this method on Reflect?
The purpose of Reflect is to contain, 1:1, a method for each Proxy trap. There is already a method on Proxy that traps hasOwnProperty (getOwnPropertyDescriptor) so it doesn’t make sense to add an additional trap, therefore it doesn’t make sense to place this method on Reflect.