Heim  >  Fragen und Antworten  >  Hauptteil

javascript - 如何理解Math.max.apply(null,a)中的null

a=[10,20,30]
alert(Math.max(10,20,30))
alert(Math.max.apply(null,a))

可以理解这里为什么要用apply,是为了让math.max可以处理数组,但是不能理解Null是什么意思?

PHPzPHPz2722 Tage vor380

Antworte allen(4)Ich werde antworten

  • 大家讲道理

    大家讲道理2017-04-11 13:14:34

    看看snandy的解释:http://www.cnblogs.com/snandy...

    Antwort
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-11 13:14:34

    表示把null传给函数中的this。因为max是不用this的,这里方便起见就传个null

    Antwort
    0
  • 阿神

    阿神2017-04-11 13:14:34

    这里不需要 this,所以随便传什么都无所谓

    Antwort
    0
  • 高洛峰

    高洛峰2017-04-11 13:14:34

    null在那里只是占了个位置,

    Math.max.apply(a,a)
    30
    Math.max.apply(999,a)
    30
    a
    [10, 20, 30]

    Antwort
    0
  • StornierenAntwort