I was reading the following abbreviated code exert from this post that gets the 'minimum' date in a list of dates:
var dates=[];
dates.push(new Date("2011/06/25"))
dates.push(new Date("2011/06/26"))
dates.push(new Date("2011/06/27"))
var minDate=new Date(Math.min.apply(null,dates));
Is someone able to explain why we need to use .apply
here?
I understand that .apply
is used to execute a function with a supplied a this
value but I don't understand why the code requires the min
function to be called with this=null
and why the code does not work when you substitute:
Math.min.apply(null, dates)
for Math.min(dates)