3 ms·
> already uncommon It's definitely not uncommon though. Just to provide one example: how often do you use all the arguments to `.map` callback? Usually you'd
by RReverser 6y ago
> already uncommon
It's definitely not uncommon though. Just to provide one example: how often do you use all the arguments to `.map` callback?
Usually you'd write something like `arr.map(x => x + 1)`.
However, to spell out all the arguments you'd have to write `arr.map((x, i, arr) => x + 1)`.
And there's tons of other functions like that in stdlib or 3rd-party libs that people use without passing or accepting all the args. That's why this optimisation is so useful.
- skrebbel 6y agoThis is exactly the kind of thing that TypeScript generated JS could help optimize. Because tsc can see that this `map` call is, in fact, Array.prototype.map, it can deduce that the lambda will get sent three values. It could generate dummy arguments for that in the JS output. It could just as easily generate a hint to the same effect in some constraint file as the GP suggests.