5

The MDN docs state:

Note: In some versions of some browsers, this method was implemented as the method Array.prototype.group(). Due to web compatibility issues, it is now implemented as a static method.

However, similar issues arose with flat (see SmooshGate) but this was resolved by renaming the term to flatten. Why didn't TC39 take the same approach with groupBy and find a non-conflicting name?

DarkBee
14.4k9 gold badges86 silver badges135 bronze badges
asked Jun 30, 2025 at 12:10
1
  • 1
    This comes up in my mind every time I wish to use groupBy... itemArray.filter(...).map(...).groupBy(...) Commented Jun 30, 2025 at 12:12

1 Answer 1

4

The original proposal states the reasoning:

Why static methods?

We've found a web compatibility issue with the name Array.prototype.groupBy. The Sugar library until v1.4.0 conditionally monkey-patches Array.prototype with an incompatible method. By providing a native groupBy, these versions of Sugar would fail to install their implementation, and any sites that depend on their behavior would break. We've found some 660 origins that use these versions of the Sugar library.

We then attempted the name Array.prototype.group, but this ran into code that uses an array as an arbitrary hashmap. Because these bugs are exceptionally difficult to detect (it requires devs to detect and know how to report the bug to us), the committee didn't want to attempt another prototype method name. Instead we chose to use static method, which we believe is unorthodox enough to not risk a web compatibility issue. This also gives us a nice way to support Records and Tuples in the future.

https://github.com/tc39/proposal-array-grouping?tab=readme-ov-file#why-static-methods

answered Jun 30, 2025 at 12:15
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.