Reputation: 6378
I have written the code
// Handlers
function successHandlerFactory (savedFlag) {
return function (res, savedFlag){
if (res.data && res.status == 200) {
ngcoupon_offerManager.addOffers(res.data.offers, -1, savedFlag);
console.log('offers response', res, 'savedFlag', savedFlag);
} else {
console.error('something is wrong to get offers', res);
}
}
};
var offerSuccessHandler = function() {
return successHandlerFactory();
}();
var savedofferSuccessHandler = function () {
return successHandlerFactory(true);
}();
but apparently its giving out savedFlag undefined
every executinon I make.
How come this does not work
Upvotes: 0
Views: 58
Reputation: 1550
The issue is in this part of the code:
function successHandlerFactory (savedFlag) {
return function (res, savedFlag){
...
You're re-declaring savedFlag
in the inner function, which ends up being the variable that is captured in the success handler. Try simply removing the second parameter of the returned function.
Upvotes: 5