Math.min.apply(0, array) - why?

后端 未结 4 1153
情话喂你
情话喂你 2020-12-13 13:31

I was just digging through some JavaScript code (Raphaël.js) and came across the following line (translated slightly):

Math.min.apply(0, x)

4条回答
  •  天命终不由人
    2020-12-13 13:53

    The proper and less confusing way to call this is: Math.min.apply(null, array)

    If parameter is unused setting it to null makes code more readable than setting it to 0 or Math

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply

提交回复
热议问题