class component()
{
Service _service = new Service();
let serviceMethod = isUpdate ? this._service.update :
this._service.create;
serviceMethod(param);
}
class Service
{
update()
{
// Other stuff
// Cannot access this here
this.privatelocalfunc();
}
create()
{
// Other stuff
// Cannot access this here
this.privatelocalfunc();
}
}
我必须有条件地在上述代码中描述的方法之间进行切换。但是,当我这样做时,我无法访问service方法的'this'变量。什么是实现这一目标的最佳方法?