Reflect.hasOwn() ?

Axel Rauschmayer axel at rauschma.de
Sat Jul 26 12:06:06 PDT 2014


On Jul 26, 2014, at 20:36 , Kevin Smith <zenparsing at gmail.com> 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).
> 
> I think that there is still a need here.

Yes, but it’s much less urgent.

> Since we are really interested in *keys*, what about this:
> 
>     Object.hasKey(obj, someKey);

Ah, good point! I hadn’t thought of symbols as property keys.

> which would be a more ergonomic and efficient way of saying:
> 
>     Object.keys(obj).some(key => key === someKey)

Did you mean `Reflect.ownKeys()`? How about:

```js
Reflect.ownKeys(obj).indexOf(someKey) >= 0
```

Or, maybe in ES7:

```js
Reflect.ownKeys(obj).contains(someKey)
```

-- 
Dr. Axel Rauschmayer
axel at rauschma.de
rauschma.de



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140726/43e214b1/attachment.html>


More information about the es-discuss mailing list