JavaScript reduce can't handle Math functions?
问题 I'm trying an obvious task: var maxVal = [ 1, 2, 3, 4, 5 ].reduce( Math.max, 0 ); and get: NaN as the result. To make it work I have to make an anonymous function this way: var maxVal = [ 1, 2, 3, 4, 5 ].reduce( function ( a, b ) { return Math.max(a, b); }, 0 ); Could someone tell me why ? Both are functions that take two arguments and both return one value. What's the difference? Another example could be this: var newList = [[1, 2, 3], [4, 5, 6]].reduce( Array.concat, [] ); The result is: [1