js对象函数如何不劫持callback函数的this指向?
function Afun(){
this.bfun = new Bfun(this.callBack);
}
Afun.prototype.callBack = function(){
console.log(this);//这个函数被`Bfun`调用时,this指的是`Bfun`,如何让它指为`Afun`?
}
function Bfun(callBack){
callBack();
}
new Afun();//输出`Bfun`,但是我希望是`Afun`
☆.大虾牛┽
9 years, 8 months ago
Answers
this.bfun = new Bfun(this.callBack.bind(this));
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glob...
高坂桐乃.
answered 9 years, 8 months ago