Suggestion: "Object.hasOwnProperty"
Object.hasOwnProperty
already exists via the prototype chain, but I'm
guessing you wish it did something different.
Both the concern of someObj.hasOwnProperty(somePropertyName)
attempting
to call the hasOwnProperty
property of someObj
rather than walking the
prototype chain to get Object.prototype.hasOwnProperty
, and the concern
of someObj
having a null prototype (or otherwise not having
Object.prototype.hasOwnProperty
on its prototype chain) can be avoided
with the {}.hasOwnProperty.call(someObj, somePropertyName)
pattern.
Both the concern of
someObj.hasOwnProperty(somePropertyName)
attempting to call thehasOwnProperty
property ofsomeObj
rather than walking the prototype chain to getObject.prototype.hasOwnProperty
, and the >> concern ofsomeObj
having a null prototype (or otherwise not havingObject.prototype.hasOwnProperty
on its prototype chain) can be avoided with the{}.hasOwnProperty.call(someObj, somePropertyName)
pattern.
Hi,
Yeah, sure. But it could be cleaner to do:
Object.hasOwnProperty(myObj, someName)
instead of
{}.hasOwnProperty.call(myObj, someName)
This would break a Web, a I have seen code that relies on Object.hasOwnProperty === Object.prototype.hasOwnProperty
Anyway, it would be handy to have such function as Reflect.hasOwn
or
something like that.
This would break a Web, a I have seen code that relies on Object.hasOwnProperty === Object.prototype.hasOwnProperty
Sorry, I didn’t remember that the constructor inherits it.
Anyway, it would be handy to have such function as
Reflect.hasOwn
or something like that.
Yeah, maybe that then. Or “System.ObjectHasOwn” or else.
I'd, for ergonomic reasons, would prefer it on Reflect. I very frequently alias this function, so having it as a static method on Reflect would be nice.
Reflect is only for API mirrors to Proxy traps - that's why Reflect.enumerate was removed along with the Enumerate Proxy trap.
I think to create "Object.hasOwnProperty". Often, an object is used to store key/value pairs and most users forget that "hasOwnProperty" can be also be a key. Objects created by "Object.create(null)" don't inherit this function and users get lost when they get such an object from a library or their own code.
Claude Petit