Tab Atkins Jr.
jackalmage at gmail.com
Sat Jul 26 23:33:30 PDT 2014
On Sat, Jul 26, 2014 at 11:36 AM, 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).
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`, unless you're allowing
undefined to be passed explicitly as a valid argument for some reason.
More information about the es-discuss