js function里面的this是什么,主要看这个function是怎么调用的
some = {}
some.method = method
some.method() // 输出some
method() // 输出global
method.call(some) // 输出some
some.method.apply({a:1}) // 输出 {a:1}
如果把 x.method()
这种叫做有主调用(主就是 . 前面的那个变量),那么函数里面的this
就是主method()
这些叫做无主调用,这时候this
就是global
call
apply
这些方法将function
的主改变为第一个参数。fun.apply( obj )
在strict mode
,有this
的函数,是不能无主调用的,会出错
在strict mode
,带this
函数的无主调用,this
的值为undefined
es6里面的箭头函数里面的this
,始终是前文的this
,比如[1,2,3].map(_=>this) // [global,global,global]
所以,你上面问的问题,无法判断this
是啥,你没有给出fire
是怎么调用的