You can use Promise.mapwith .bind:
function getComponentStatuses(componentsToCheck) {
return Promise.map(componentsToCheck, function() {
var start = Date.now();
return getAsync({
url: component.endpoint,
timeout: component.timeout
})
.bind({
name: component.name,
status: null,
body: null,
time: null
})
.spread(function(response, body){
Logger.info('GET took ' + end + 'ms.');
this.status = response.statusCode;
this.body = body;
return this;
})
.catch(function(e) { return this; })
.finally(function() { this.time = Date.now() - start; })
});
}
, , http .