Array.prototype.toObjectByProperty( element=> )

Darien Valentine valentinium at
Fri Aug 11 06:25:02 UTC 2017

@Alexander The idea of a generalized `map` function (etc, I’m guessing) is
appealing. From the way you talked about it, it sounds like there may have
past discussion on the topic. Are there any proposals for this or major
being batted around?

> Why? What's the advantage? You lose at least the square bracket and dot
> notations for access, as disadvantages, and I'm not aware of any
> If there aren't any that compensate for the disadvantages, then it's a net
> negative

@Naveen — a handful of things. Objects are indeed a perfectly reasonable
for modeling kvp collections a lot of the time. On the other hand, because
objects in ES serve double duty as ways to model data and ways to "model
they are not always ideal for the former case on account of the features
exist mainly to serve the second. Some examples of things that make maps
inherently iterable; no prototype chain access lookup; no collision with
`Object.prototype` property name when hashing by arbitrary keys; potentially
more efficient for situations where keys are frequently removed;
`map.has()` is
more straightforward than having to consider whether you want `key in` or
`Object.hasOwnProperty` or which properties have been defined as enumerable
not; iteration order of entries is 1:1 with insertion order; and of course,
can be of any type. Further, maps can be subclassed to constrain the types
they may hold or add other behaviors without needing to define custom

Some general use cases: registries; hashing data where keys are from
input; kvp collections which are ordered; kvp collections which will be
to later transformations; kvp collections to which new keys are frequently
or removed.

While I hope that information is somewhat helpful, there are probably much
detailed resources online (including, I suspect, past discussions on this
which could explain some of those things better or which include cases I
thought of.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list