[dev-platform] Intent to prototype: Object.hasOwn

19 views
Skip to first unread message

Yulia Startsev

unread,
Jun 8, 2021, 11:53:11 AM6/8/21
to firef...@mozilla.org
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

Test262: Tests are in progress and will be merged when they land.

best,
Yulia

--
You received this message because you are subscribed to the Google Groups "firef...@mozilla.org" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firefox-dev...@mozilla.org.
To view this discussion on the web visit https://groups.google.com/a/mozilla.org/d/msgid/firefox-dev/CAPxDkP-H1MVhtCeiG%3DGi7Z1B%3DxF%3D7i8dqfJ8va0PN6fO%2BWtC%3Dg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages