I am using async each to loop through and constructing an object called coupon_bo
. Surprisingly inside processbo
function, I am seeing a side effect where only the last copy of coupon_bo
object is available to processbo
function.
My understanding is that since coupon_bo
is local to each iteration, there should be a new object for iteration.
Am I missing something?
function hitApplyLogic(coupon_names, coupons_list, req, callback) {
async.each(coupon_names, function(coupon_name, callback) {
var coupon_bo = new coupon_objects.CouponsBO();
coupon_bo.incoming_request = req.body;
coupon_bo.incoming_request['coupon_code'] = coupon_name.cn;
coupon_bo.incoming_request['list_offers'] = true;
setTimeout(function()
{
console.log("CONSOLE-BO: " + JSON.stringify(coupon_bo));
}, 1000);
});
}