Reflect.hasOwn() ?

Rick Waldron waldron.rick at gmail.com
Sun Jul 27 15:07:21 PDT 2014


On Sunday, July 27, 2014, Tab Atkins Jr. <jackalmage at gmail.com> wrote:

> On Sat, Jul 26, 2014 at 11:36 AM, Kevin Smith <zenparsing at gmail.com
> <javascript:;>> wrote:
> >> * As far as I can tell, `hasOwnProperty` is mainly used to implement
> maps
> >> via objects. `Map` will eliminate this use case.
> >
> > To a certain extent yes, but not completely.  Objects-as-maps will still
> be
> > used quite frequently as object literals passed into functions (as an
> > options object, for example).
>
> In that case, though, you don't want to use `hasOwnProperty`; you want
> to allow property bags to express properties on the proto (for
> example, as getters).  So this particular use-case of objects-as-maps
> is irrelevant for the question at hand.
>
> > I think that there is still a need here.  Since we are really interested
> in
> > *keys*, what about this:
> >
> >     Object.hasKey(obj, someKey);
> >
> > which would be a more ergonomic and efficient way of saying:
> >
> >     Object.keys(obj).some(key => key === someKey)
>
> This is identical to `obj.key !== undefined`,


As long as "key" is enumerable.


Rick



> unless you're allowing
> undefined to be passed explicitly as a valid argument for some reason.




>
> ~TJ
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org <javascript:;>
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140727/69288fa6/attachment.html>


More information about the es-discuss mailing list