javascript - function executed by .apply() works with array, but does not the original function -


if math.max([1,3,9]) returns error (needs list of numbers, not array), why calling via apply below works?

function getmaxofarray(numarray) {  return math.max.apply(null, numarray); }  getmaxofarray([1,3,9]) //9  getmaxofarray(1,3,9) //error 

i understand .apply passes array, why should max function work them when called via apply? there internal transformation array => list ?

apply expects parameters in array. if have parameter list how in second case, use call instead

math.max.apply(null,[1,3,9]) math.max.call(null,1,3,9) 

what difference between call , apply? goes amount of detail on difference between call , apply


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -