2
我對這些保證承諾有些困惑,無法理解爲什麼我不能將承諾退還給另一承諾。我的問題是下面,我有一個函數保存:JavaScript/Node.JS在另一個承諾不起作用的情況下返回承諾
save(Driver) {
this.exists(Driver).then(exist => {
if(exist) {
return new Promise(function (resolve, reject) {
if (exist === true) {
resolve(true);
} else if (exist === false) {
resolve(false);
} else {
reject(err);
}
});
}
});
};
容易,因爲它是,當我嘗試調用該函數如下:
save(driver).then(this.common.saveSuccess(res))
.catch(this.common.noSuccess(res));
我收到一個錯誤說, Cannot read property 'then' of undefined
,我不明白爲什麼,因爲我回來的承諾。 感謝您的幫助
你沒有返回從'保存任何東西()'。 '返回this.exists(驅動程序)。然後(...'另外,結果'定義在哪裏? – Ryan
是的抱歉,我試圖簡化代碼,並忘記喲更改文本,我修正了 –
請修復它的問題 – Ryan