I have the following code in a function :
for (var key in handlers) {
var handler = new handlerClass(key);
handler.search(user.login, function(userFound) {
if (!userFound) {
handler.create... //Here handler is the last handler of the loop
}
});
}
I understand what appens, the loop finish before handler.create is called, so when it is called handler is equal to the last handler of the loop.
How can I solve this ?