My question involves promises and providing previous values of chain promises. The question is, is the item passed from first return promise to second promise "runItem --> testItem"?
Or do we have to pass the item through all promises?
Example:
db.items.find({_id: id}).then(function (res) {
runItem(item);
})
function runItem(item) {
removeFromQueue(item.id).then(function () {
testItem(item);
});
}
function testItem(item) {
...
}
function removeFromQueue(item) {
return db.queue.remove({_id: item._id});
}
EDIT: Maybe this would be a better example:
Can we access original attribute item, or is it going to be overwritten when the next time function is called?
function start(id)
db.find({_id: id}).then(function (item) {
test(item).then(function (res) {
// can we access original attribute item, or is it going to be overwritten when the next time function is called
resolve({ res: res, item: item });
});
});
}
function test(item) {
return $test(item).then(function () {
resolve('success');
});
}