暴露给js的对象内部不能使用this(undefined)。

暴露给js的对象内部不能使用this(undefined)。

HarmonyOS
2024-05-30 23:05:00
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
makeer

可以使用箭头函数,这样this就会指向类的实例:

class testclass { 
  text: string 
 
  constructor() { 
    this.text = '测试文本' 
  } 
 
  test = (): string => { 
    return this.text; 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
分享
微博
QQ
微信
回复
2024-05-31 22:18:11


相关问题
ts 声明式开发不能使用jsgetApp()
5004浏览 • 1回复 待解决
xComponet示例代码不能使用
1422浏览 • 1回复 待解决
应用卡片内部组件能使用装饰器吗?
644浏览 • 1回复 待解决
HarmonyOS hap中不能使用命名路由吗
477浏览 • 1回复 待解决
HarmonyOS .ets文件中不能使用方法重载
387浏览 • 1回复 待解决
json解析对象后获取数据返回undefined
1424浏览 • 1回复 待解决