The existing squareValues example is misleading in the sense that it makes a reader believe that values is (naturally) an array of passed values. However, values in the example is actually an array of arguments arrays:
Coincidentally, multiplying arrays [ 2 ] * [ 2 ] gives 4 in Javascript, which obscures the fact that values consists of arrays rather than values. But this conversion is not going to take place in most other circumstances. For instance, if you return val + val instead of val * val in your example, the debounced promise will resolve to 11 22 33 44 instead of 1 2 4 8.
The PR makes it more obvious to infer the actual API from the example:
The existing
squareValues
example is misleading in the sense that it makes a reader believe thatvalues
is (naturally) an array of passed values. However,values
in the example is actually an array of arguments arrays:Coincidentally, multiplying arrays
[ 2 ] * [ 2 ]
gives 4 in Javascript, which obscures the fact that values consists of arrays rather than values. But this conversion is not going to take place in most other circumstances. For instance, if you returnval + val
instead ofval * val
in your example, the debounced promise will resolve to11 22 33 44
instead of1 2 4 8
.The PR makes it more obvious to infer the actual API from the example:
Another options would be to use arguments destructuring:
but I think it's even harder to comprehend.