- var name=222
- var a={
- name:111,
- say:function(){
- console.log(this.name)
- }
- }
-
- var fun=a.say
- fun() //fun.call(window) //222
- a.say() //a.say.call(a) //111
-
- var b={
- name:333,
- say:function(fn){
- fn()
- }
- }
- b.say(a.say) //fn() fun.call(window) //222
- b.say=a.say //把a里的say函数直接赋值给b.say
- b.say() //b.say.call(b) //333
通过使用call来确定this指向。