I'm trying to get my head around what JavaScript's apply()
method actually does. I'm using this as a reference: http://ejohn.org/blog/fast-javascript-maxmin/, in which apply()
is used to give Array
a min()
function.
Array.min = function( array ){
return Math.min.apply( Math, array );
};
How does apply()
work here? I get that Math.min()
can't take an array as an argument, but I'm having trouble visualizing how apply()
turns the array into a list of arguments that Math.min
understands.