javascript - 如何理解Math.max.apply(null,a)中的null
PHPz
PHPz 2017-04-11 13:12:34
0
4
376
a=[10,20,30]
alert(Math.max(10,20,30))
alert(Math.max.apply(null,a))

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

PHPz
PHPz

学习是最好的投资!

répondre à tous(4)
大家讲道理

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

伊谢尔伦

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

阿神

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

小葫芦

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

Math.max.apply(a,a)
30
Math.max.apply(999,a)
30
a
[10, 20, 30]
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!