1.首先了解一下call和apply

call 和 apply 的第一个参数是null/undefined时函数内的this指向window 或global

call/apply 用来改变函数的执行上下文(this),它们的第一个参数thisArg 是个对象,即作为函数内的this,多数的时候你传啥函数内就是啥,以call为例:

注意:传入null 或者undefined 时,将是JS执行环境的全局变量,浏览器中是window ,其他环境(如node) 则是global.

2. Math.max.apply(null,arr)

这里表示把null 传给函数中的this,因为max是不用this的,所以随便传什么都无所谓,只是个占位符

Math.max.apply(null,arr)求最大值的更多相关文章

  1. 如何用Math.max.apply()获取数组最大/小值

    最近似乎对JavaScript有点兴趣了~~~打算好好钻研这个东西.可是,一开始就遇到问题了!!! Math.min.apply(obj,args);//这个obj对象将代替Function类里thi ...

  2. Math.max.apply()用法

    apply的一些其他巧妙用法 Math.max.apply( null, [12,23,34,45] ); //细心的人可能已经察觉到,在我调用apply方法的时候, // 第一个参数是对象(this ...

  3. Math.min() Math.max() Math.min().apply() Math.max() .apply()该如何使用???

    Math.min()和 Math.max()  语法: Math.min(x,y) Math.max(x,y) 虽然能取到最小值和最大值,但是不支持数组. 那么如何计算数组中的大小值呢???????? ...

  4. JavaScript数组求最大值 面试题

    1.JavaScript数组求最大值 (1)方法一:借用math.max (2)方法二:ES6 2.代码 <!DOCTYPE html> <html lang="zh&qu ...

  5. JS 数组求 最大值、最小值、平均值以及求和方法

    function arrMaxNum2(arr) { return Math.max.apply(null, arr); } function arrMinNum2(arr) { return Mat ...

  6. Math.max得到数组中最大值

    Math.max(param1,param2) 因为参数不支持数组. 所以可以根据apply的特点来解决, var max = Math.max.apply(null,array),这样就可以轻易的得 ...

  7. js求最大值最小值

    比较数组中数值的大小是比较常见的操作,比较大小的方法有多种,比如可以使用自带的sort()函数,代码如下: <html> <head> <meta charset=&qu ...

  8. Javascript中的Math.max()和Math.min()

    Math.max()是求最大值,Math.min()是求最小值 Math.max(value1,value2,value3....) 但是如果是数组或者对象呢? var numArr = [1,2,4 ...

  9. JS数组求最大值和最小值

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

随机推荐

  1. Hadoop -- ES -- CURD

    1.获取ES连接 package com.ciic.history.common; import org.elasticsearch.client.transport.TransportClient; ...

  2. nginx-启动|关闭|重新加载配置文件的命令

    1.1 进入操作目录 D: cd D:\NginxTest\nginx-1.10.2 1.2 启动指令 nginx -c conf\nginx.conf 1.3 关闭指令 nginx -s stop ...

  3. phpcms v9 的表单向导功能的使用方法 附多个案例

    本文主要介绍phpcms v9的表单向导功能是如何使用的,并副多个案例讲解: 先介绍一下v9 的表单向导如何使用 表单向导做的很实用,生成一个表单,常用的是把它作为一个留言板,或者在招聘栏目作为一个供 ...

  4. 安装了nodejs后在命令行运行npm报错

    安装了nodejs后在命令行运行npm报错:Error: Cannot find module 'internal/util/types' 解决方法:删除目录“C:\Users\mengxiaobo\ ...

  5. [No000012F]WPF(7/7) - 样式,触发器和动画

    WPF Tutorial : Beginning [^] WPF Tutorial : Layout-Panels-Containers & Layout Transformation [^] ...

  6. In abstract algebra, a congruence relation (or simply congruence) is an equivalence relation on an algebraic structure (such as a group, ring, or vector space) that is compatible with the structure in

    https://en.wikipedia.org/wiki/Congruence_relation In abstract algebra, a congruence relation (or sim ...

  7. composer命令详解

    composer命令行 你已经学会了如何使用命令行界面做一些事情.本章将向你介绍所有可用的命令. 为了从命令行获得帮助信息,请运行composer或者composer list 命令,然后结合--he ...

  8. 表单中Readonly和Disabled的区别:readonly在get和post可传值到后端,disabled不可

    http://www.nowamagic.net/html/html_ReadonlyAndDisabled.php Readonly和Disabled是用在表单中的两个属性,它们都能够做到使用户不能 ...

  9. zookeeper 杂记

    Zookeeper为了保证高吞吐和低延迟,在内存中维护了这个树状的目录结构,这种特性使得Zookeeper不能用于存放大量的数据,每个节点的存放数据上限为1M.

  10. Oracle shrink table

    shrink必须开启行迁移功能. alter table table_name enable row movement ; 在oracle中可以使用alter table table_name shr ...