Giter VIP home page Giter VIP logo

proposal-accessible-object-hasownproperty's People

Contributors

bnb avatar icecream17 avatar jamiebuilds avatar nicolo-ribaudo avatar timvdlippe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

proposal-accessible-object-hasownproperty's Issues

Request to extend the proposal with a `Object.hasOwnEnumerable()` method

Rationale:
We need a counterpart to Object.keys() and Object.values(). (Object.hasOwn() being a counterpart to Reflect.ownKeys()).
I think checking has-own&enumerable is a far more common use-case than just has-own. I have seen lots of flawed code in the wild that assumes hasOwnProperty is a counterpart to Object.keys(). See: facebook/react#19921

Suggestions for a better name are welcome... propertyIsEnumerable is rather awkardly named.

Here's a polyfill:
Object.hasOwnEnumerable = Function.prototype.call.bind(Object.prototype.propertyIsEnumerable);

Naming bikeshed

I perfectly understand that has is more frequent name than hasOwn for this shortcut, but we have Reflect.has which works like in operator. The rest Reflect methods work similarly to Object methods - we should avoid this inconsistency. Also, I think, the method name should point to check own properties.


Edit from @jamiebuilds:

This proposal was presented to TC39 on April 20, 2021, where it went forward to Stage 2 but the name was left in question. This issue should be used for discussing the method name further.

Publish

How about publishing the package to let folks make use of the polyfill? You already have the main field, etc. Thanks!

Stage 3 review

  • spec still needs to be renamed to hasOwn
  • I don't understand the note - i think it's trying to explain why ToPropertyKey throws before ToObject, but the wording implies it's for legacy compatibility, and there is no previous Object.hasOwn. In other words, if it's important to make the function truly be identical to Object.prototype.hasOwnProperty, the note needs better wording; however, it seems better to me to do the ToObject first?

Consistency with keys/values might ask for different semantic with hasOwnProperty

As the faq why name has, "it fills in a hole in the common operations between Object, Map, and Set."

So I assume the new API should keep the semantic consistency with keys/values methods.

Map/Set all satisfy the invariant of: collection.has(key) === [...collection.keys()].includes(key)

If we also want the invariant of Object.has(o, key) === Object.keys(o).includes(key), the semantic of has() should only return true for enumerable string keys, which is different with Object.prototype.hasOwnProperty.

Tracking issue for tc39 process requirements

Stage 1

  • introduced to TC39 (Presented on April 20, 2021)
  • champions identified (@bnb)
  • initial explainer (Explainer)

Stage 2

Stage 3

Stage 4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.