const args = [11, 12]add.apply(null, args);
第一个参数传递null的意义?
1 回答
湖上湖
TA贡献2003条经验 获得超2个赞
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]) // nulladd.apply(undefined, [11, 22]) // undefinedadd.apply(1, [11, 22]) // 1添加回答
举报
0/150
提交
取消
