在HarmonyOS NEXT开发中ets中设置监听回调的方法中无法使用this?

在HarmonyOS NEXT开发中ets中设置监听回调的方法中无法使用this?在ets中不支持监听的callback中调用当前this下的别的方法,报this是个undefined错误

class A{ 
  b() {} 
  callback() { 
    this.b(); 
  } 
  Register() { 
    on("xxx", this.callback) 
  } 
  Unregister() { 
    off("xxx", this.callback) 
  } 
}
阅读 646
1 个回答

使用箭头函数 on("xxx", () => this.callback())