for(var i=1; i<496; i++) {
(function(num) {
myApp.getTerm(num, function (term, def){
myApp.quizlet[0].terms[num] = { term: term, definition: def};
});
})(i);
};
I’m calling a function with callback inside a for-loop. The callback function need to access the current loop’s iteration i. I’m coming up with the solution above.
Is there any other way to do things like this?
It’s more readable to define a named function to call:
Other than that, I don’t know what you can do.