Math.max.apply()如何工作?
 Math.max.apply()如何工作? 
 <!DOCTYPE html> <html> <head> <meta charset=utf-8 /> <title>JS Bin</title> </head> <body> <script> var list = ["12","23","100","34","56", "9","233"]; console.log(Math.max.apply(Math,list)); </script> </body> </html> 
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max
 上面的代码查找列表中的最大数量。 谁能告诉我下面的代码是如何工作的? 这似乎工作,如果我传递null or Math. 
 console.log(Math.max.apply(Math,list)); 
 所有的user-defined/Native functions都有调用和应用方法,我们可以使用? 
  apply接受一个数组,并将该数组作为参数应用于实际函数。 所以, 
 Math.max.apply(Math, list); 
可以理解为,
 Math.max("12", "23", "100", "34", "56", "9", "233"); 
 所以, apply是一个方便的方法来将一个数组数组作为parameter passing给一个函数。 记得 
 console.log(Math.max(list)); # NaN 
 将不起作用,因为max不接受数组作为input。 
 还有另外一个好处,就是使用apply ,你可以select你自己的上下文。 你通过apply任何函数的第一个参数,就是this函数里面的这个。 但是, max不依赖于当前的上下文。 所以,任何事情都可以在Math起作用。 
 console.log(Math.max.apply(undefined, list)); # 233 console.log(Math.max.apply(null, list)); # 233 console.log(Math.max.apply(Math, list)); # 233 
 由于apply实际上是在Function.prototype定义的 ,所以任何有效的JavaScript函数对象都会默认apply函数。 
谁能告诉我下面的代码是如何工作的?
 Math.max.apply(Math,list) 
 用Math对象调用Math.max函数,将其用作函数实现(body)和list中的引用,作为parameter passing。 
所以这最终等于
 Math.max("12","23","100","34","56", "9","233") 
这似乎工作,如果我传递null或math。
  Math.max实现显然不使用实例variables – 没有理由这样做。 天真的实现只是迭代arguments并find最大的一个。 
所有的用户定义/本机函数都有调用和应用方法,我们可以使用?
 是的,每个函数都可以使用call或apply来调用 
参考文献:
-   MDN .apply()文档 (信贷给@RGraham )
在JavaScript ES6上只使用Spread运算符 :
 var list = ["12","23","100","34","56","9","233"]; console.log(Math.max(...list)); // ^^^ Spread operator 
Math.max(val1,val2,…)
 Math.max(1, 2, 3); // Math.max([value1[, value2[, ...]]]) 
  value1, value2...是参数,必须是Numbers MDN Math.max 
 您不能将array作为Math.maxparameter passing。 要传递一个数组,你必须使用apply 。 
应用
  apply的第一个参数是this ,第二个是array 。 math方法相当于其他语言的静态,这意味着它不需要一个对象实例,而不像array.prototype.slice所以在这种情况下你不需要传递this 。 
例
 var arr = [1, 2, 3]; Math.max(1, 2, 3); // -> 3 Math.max(arr); // -> NaN (Not a Number) Math.max.apply(null, arr); // Math.max.apply(null, [1, 2, 3]) -> Math.max(1, 2, 3) -> 3 arr.slice(1); // -> returns Array [2, 3] Array.prototype.slice.call(arr, 1); // Array.prototype.slice.call([1, 2, 3], 1) == [1, 2, 3].slice(1) 
 当你想传递一个数组作为参数时,你必须使用apply ,否则使用call 。 
  一个 pply = 一个 rray 
  c all = c omma分隔 
  更多关于通话和申请