Hi Everyone,
This proposal adds to JavaScript an ergonomic way to check if a property exists directly on an object, and not on it's prototype chain. It is a small proposal, but this is tricky to get right, as it will throw on objects such as Null.
A common implementation is:
let hasOwnProperty = Object.prototype.hasOwnProperty
if (hasOwnProperty.call(object, "foo")) {
console.log("has property foo")
}
Which can now be simplified to
if (Object.hasOwn(object, "foo")) {
console.log("has property foo")
}
Platform coverage: All.
Preference: None, available only on Nightly.
DevTools bug: None.
Other browsers:
1. Google Chrome supports this behind a flag --harmony-object-has-own
2. Safari: Not supported yet
best,
Yulia