2 回答

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超3個贊
您缺少function關(guān)鍵字:
async function mymethod(onSuccess, onFailure) {
try {
// Do some here
onSuccess()
}
catch (e) {
//this was an error
onFailure()
}
}
mymethod(() => alert('success'), () => alert('failure'));

TA貢獻(xiàn)1775條經(jīng)驗(yàn) 獲得超8個贊
由于您使用的是打字稿和 a,因此class您需要包含public訪問修飾符,因?yàn)榉椒ㄊ莗rivate默認(rèn)的。
class Foo {
public async mymethod(onSuccess, onFailure) {
try {
// Do some here
onSuccess()
}
catch (e) {
//this was an error
onFailure()
}
}
}
const foo = new Foo();
foo.mymethod(() => { console.log('success') }, () => { console.log('failure') });
添加回答
舉報(bào)