Closed oleedd closed 2 months ago
It will not break anything.
O RLY? I used something like set1.forEach(set2.add, set2)
too often.
I don't understand what you mean, this code is not complete. What is the problem? Browsers just ignore another arguments.
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
.
Do you mean that you passed several items instead of 1 expecting that only 1 will be added? It is not right usage.
It is not right usage.
Apparently, you know better :-D However, this is a frequent case.
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.
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.
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()
.