. , .map() Promise.all() .reduce(), :
function getXkcd(count) {
var ids = new Array(count).fill(1).map((val, index)=>index+1)
}
, . . xkcd , , ...
function getXkcd(max, last) {
var current = last ? last + 1 : 1;
xkcd(current)
.then(function(title) {
result += title;
})
.then(getXkcd.bind(null, max, current))
.catch(function(error) {
});
}
. , bind . , : getXkcd(50, 15); .
, :
function getXKCD(max, start) {
var result = "";
var getNext = function(id){
if (id > n) {
return result;
}
return xkcd(id)
.then(function(title){
result += title;
return id + 1;
})
.then(getNext);
}
return getNext(start || 1);
}
getXKCD(50).then(function(results){
}, function(error){
});
getXKCD getNext, Promise. , . bind, " " .