Usually, defining a variable outside functions is enough to let it be "global". In my case, however, situation seems to be different.
var username = null;
function myFunction_1() {
username="pippo";
myobject.myfunction(function (data){ username="mickey" })
console.log("1: ", username);
}
myFunction_1();
I expected this code to log "1: mickey". However, if i set the variable inside a callback function logs "1: pippo", that is setting inside the callback gets ignored.
What i'm missing? Setting variable in this way is not enough?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…