Re:TC39: Add Object.groupBy and Map.groupBy
by LegionMammal978 on Tuesday December 19, 2023 @05:22PM
(#38702692)
Map.groupBy() returns a Map with the keys mapped to array values. In parallel, Object.groupBy() returns an Object with the keys cast into property names. Thus, I'd say it fits the pattern of Object-related static methods, since it's using the Object mechanism as a map.
[ Parent
| on HN ]
Re:TC39: Add Object.groupBy and Map.groupBy
by zeroimpl on Tuesday December 19, 2023 @06:22PM
(#38703358)
The part I’m confused on is the documentation saying the returned object from Object.groupBy doesn’t extend from Object.prototype. Is it still an object?
The return value of groupBy is an object that does not inherit from %Object.prototype%.
Re:TC39: Add Object.groupBy and Map.groupBy
by edflsafoiewq on Tuesday December 19, 2023 @06:28PM
(#38703420)
It's called a null-prototype object: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
They're "usually used as a cheap substitute for maps": the lack of prototype prevents the object from being polluted by keys that morally shouldn't be there, like toString, etc.
Re:TC39: Add Object.groupBy and Map.groupBy
by aragonite on Tuesday December 19, 2023 @06:44PM
(#38703570)
It's a value that belongs as a member of the Object data type (Object(it)===it), but it's not (in addition) an instance of the Object constructor (!(it instanceof Object)). I guess the former, wider sense of 'an object' is more often intended.