["1", "2", "3"].map(parseInt)
> [1, NaN, NaN] ["1", "2", "3"].map(parseInt)
> [1, NaN, NaN]Map calls a function with "currentValue", "index", and "array".
So the calls essentially look like this:
parseInt("1", 0, arrayReference) // => 1
parseInt("2", 1, arrayReference) // => NaN
parseInt("3", 2, arrayReference) // => NaNWhy are they not equivalent?
EDIT: Never mind, another comment explained this.
More generally, javascript functions accepting any number of parameters, regardless of those specified in the function declaration, is quite error prone when passing functions around.
I always use anonymous functions or 'bind' to explicitly match the parameters unless all functions involved are curried.
The other reason to avoid passing 'naked' functions around too happily is the behavior of this.
I also find most optimizations to focus on simple, explicit code. Nothing like using the less common, more dynamic features of the language to hit deoptimizations.
["1", "2", "3"].map(_.bind(parseInt, null, _, 10));
=> [1, 2, 3]