【发布时间】:2016-01-28 22:30:41
【问题描述】:
我正在使用 Promise 并关注 another example,但是当我运行脚本时出现错误 TypeError: Cannot read property 'then' of undefined。我的代码如下所示:
var completedLinks = ["http://www.example.com/1","http://www.example.com/2","http://www.example.com/3"]
function fetchSiteDetails(arr){
arr.reduce(function(promise, email) {
console.log(email)
}, Promise.resolve());
}
fetchSiteDetails(completedLinks).then(function() {
console.log('all done');
});
我猜fetchSiteDetails 对使用then 无效,但我不知道为什么?
【问题讨论】:
-
fetchSiteDetails 不返回承诺? :)
-
除了在 reduce 中登录到控制台之外,您还在做什么?如果每个循环都是异步的,则需要多个 Promise
-
首先需要使用 Promise 的异步任务在哪里?
标签: javascript promise