1 回答
TA貢獻1848條經驗 獲得超2個贊
它們按照它們被調用的順序啟動,但是因為它們是異步的,所以它們可能不會按照它們被調用的順序運行。它們立即返回并返回一個 unresolved Promise,當被調用函數完成時,它最終將異步解析(或拒絕)。
您需要依次標記您的功能async和await每個調用:
$("#signUpForm").validator().on("submit", async function(event) {
if (event.isDefaultPrevented()) {
// handle the invalid form...
sformError();
ssubmitMSG(false, "Please fill all fields!");
} else {
// everything looks good!
event.preventDefault();
//create use when form is submit
await ssubmitForm();
//send email verification
await sendEmailVerification();
//sign out the user
await signOut();
}
});
為了更好地理解async/ await,我建議先學習 promises。它們是讓一切運轉起來的基礎模型;async/await只是最上面的語法糖。
添加回答
舉報
