javascript - Different callback inside the loop -
i have problem iterating in array inside callbacks. it's specific problem.
i have loop:
arr.foreach(function(value, index, array){});
inside loop call asynchronous function:
arr.foreach(function(value, index, array) { asfun1(function(i, val){ return function (param1, param2) { };}(index, value)); });
after callback fired, need set new callback object , call asynchronous function:
arr.foreach(function(value, index, array) { asfun1(function(i, val){ return function (param1, param2) { obj.callback = (function(in, v){ return function (param3, param4) { //make };}(i, val)) obj.asfun2(); };}(index, value)); });
so, solve problem implemented in obj class callback array , iterator. , in loop i'm not setting callback, adding in array. , when first callback fires, command obj iterator go next callback:
arr.foreach(function(value, index, array) { asfun1(function(i, val){ return function (param1, param2) { obj.callback.addcallback(function(in, v){ return function (param3, param4) { obj.nextcallback(); //make };}(i, val)) obj.asfun2(); };}(index, value)); });
but when test it, value , index last in array. i've tried lot of ways solve it, doesn't work.
Comments
Post a Comment