暴露给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; 
  } 
}
分享
微博
QQ
微信
回复
2024-05-31 22:18:11
相关问题
ts 声明式开发不能使用jsgetApp()
5862浏览 • 1回复 待解决
xComponet示例代码不能使用
2047浏览 • 1回复 待解决
应用卡片内部组件能使用装饰器吗?
1097浏览 • 1回复 待解决
HarmonyOS .ets文件中不能使用方法重载
994浏览 • 1回复 待解决
HarmonyOS hap中不能使用命名路由吗
960浏览 • 1回复 待解决
json解析对象后获取数据返回undefined
2304浏览 • 1回复 待解决