zoukankan      html  css  js  c++  java
  • 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内部指向

  • 相关阅读:
    bzoj3211 花神游历各国
    bzoj1010
    day8
    day6&7
    bzoj1087
    noi同步赛day1
    bzoj1076
    day3&4&5
    bzoj1079 dp
    cholesky分解
  • 原文地址:https://www.cnblogs.com/zhangzs000/p/6251057.html
Copyright © 2011-2022 走看看