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`
闭关修行中......
this.bfun = new Bfun(this.callBack.bind(this));
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glob...
function Afun() { this.bfun = new Bfun( this.callBack.bind(Afun) ); }
this.bfun = new Bfun(this.callBack.bind(this));
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glob...