我有一組 URL,我必須使用 JS / Cordova 異步函數(shù)下載它們。我當(dāng)前的實(shí)現(xiàn)看起來像這樣(簡化):var urls = [ ...... many many ...... ]var arrayPointer = 0;downloadData();function downloadData() { if(arrayPointer >= urls.length) { do_something_else(); return false } downloadURL(urls[arrayPointer++],successDownloadCallback,failDownloadCallback); return false;}function failDownloadCallback() { logError(); downloadData(); return false;}function successDownloadCallback(data) { saveDataToFile(data,saveSuccessCallback,saveFailCallback); return false;}function saveFailCallback() { logError(); downloadData(); return false;}function saveSuccessCallback() { downloadData(); return false;}不幸的是,我有時會收到“超出最大調(diào)用堆棧大小”的錯誤。有一個更好的方法嗎?
如何使用異步函數(shù)正確地遍歷數(shù)組
HUWWW
2023-05-25 17:16:40