apply的第一个参数是函数中的this值,如果add函数里面没有用到this,那么这个this参数就可以随便传入一个值,但是为了简便一般就传入null,当然你传入1,undefined,'hello'都可以,只不过都习惯传入null,代表函数里面并没有用到this的值: 'use strict'; function add (a, b) { console.log(this) return a + b } add.apply(null, [11, 12]) // null add.apply(undefined, [11, 22]) // undefined add.apply(1, [11, 22]) // 1
apply
的第一个参数是函数中的this
值,如果add
函数里面没有用到this
,那么这个this
参数就可以随便
传入一个值,但是为了简便一般就传入null
,当然你传入1,undefined,'hello'
都可以,只不过都习惯传入null
,代表函数里面并没有用到this
的值: