gpt4 book ai didi

javascript - 在 es2017 中,从异步方法访问时 'this' 未定义

转载 作者:行者123 更新时间:2023-11-29 23:52:52 26 4
gpt4 key购买 nike

<分区>

从异步方法调用时如何引用类实例。

class Senders {
callSendAPI() {
//Some code here
}
sendText() {
this.callSendAPI();
}
async sendCards() {
var dbpromise = await db.call();
console.log('this= ', this);
this.callSendAPI();
}
}
export {Senders};

this= undefined

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com