call和apply求最大和最小值

  1. ,取最大值  
  2.   
  3. var arr = [1,3,7,22,677,-1,2,70];  
  4.   
  5. Math.max.apply(Math, arr);//677  
  6. Math.max.call(Math, 1,3,7,22,677,-1,2,70);//677  
  7.   
  8.   
  9. 2,取最小值  
  10.   
  11. var arr = [1,3,7,22,677,-1,2,70];  
  12. Math.min.apply(Math, arr);//-1  

   
    1. 可以换成this
    2. document.write(Math.max.apply(this, arr));//677 
      document.write("<br/>")
      document.write(Math.max.apply(Math, arr));//677

 
  1. Math.min.call(Math, 1,3,7,22,677,-1,2,70);//-1  

call和apply改变函数this内部指向

原文地址:https://www.cnblogs.com/zhangzs000/p/6251057.html