【发布时间】:2016-12-03 08:31:12
【问题描述】:
我想在回调函数中去掉 _this/self/$this 辅助变量。我写:
export class someClass {
someFunction = function( ) {
this.foo = "bar";
this.anotherClass.doSomething( this, function( foo ) {
console.log( this.foo, "/", foo ); // "bar / another bar"
} );
}
}
和
export class anotherClass {
anotherFoo: string = "another bar";
doSomething( _this, cb ) {
cb.call( _this, this.anotherFoo );
}
}
有没有更简单的方法来做到这一点?我想去掉'this'参数。
【问题讨论】:
标签: javascript callback this