tc39 / proposal-collection-methods

https://tc39.github.io/proposal-collection-methods/
Other
172 stars 8 forks source link

Extending old methods #50

Closed oleedd closed 2 months ago

oleedd commented 1 year ago

Why do you add new methods instead of making .add() and .delete() work with several values? It will not break anything. The more names, the worse. There is no .pushAll().

zloirock commented 1 year ago

It will not break anything.

O RLY? I used something like set1.forEach(set2.add, set2) too often.

oleedd commented 1 year ago

I don't understand what you mean, this code is not complete. What is the problem? Browsers just ignore another arguments.

zloirock commented 1 year ago

There is enough here to understand what will be broken - in this case, .forEach pass to the callback 3 arguments - in case of extending .add, all of them will be added to set2 via .add.

oleedd commented 1 year ago

Do you mean that you passed several items instead of 1 expecting that only 1 will be added? It is not right usage.

zloirock commented 1 year ago

It is not right usage.

Apparently, you know better :-D However, this is a frequent case.

oleedd commented 1 year ago

I think that you don't have to consider illegal cases. Because you will have 2x more methods because of that. Just a suggestion. And to not differ from .push(). And people will still be able to fix their illegal usage. They just used that it didn't throw an error.

bakkot commented 1 year ago

In many engines, spread arguments max out at less than a million elements. For example, running Math.max(...Array.from({ length: 200_000 }, x => 1)) in Chrome throws a "Maximum call stack size exceeded" error, for me.

So even if it were web compatible, that would only work for relatively small collections.