var myUser = (function () {
var username = "",
var isConnected = false;
return {
setUsername: function (n) {
username = n;
},
setConn: function (connStatus) {
isConnected = connStatus;
},
user: username,
isCon: isConnected
};
}());
When I call
myUser.setUsername("user123");
username variable does not get updated.
Any advice?
It looks like you want to use myUser.user to refer the updated username value.
However, if that’s the case, it doesn’t work. setUsername updates username variable, but myUser.user only points to username’s initial value, which is “”. It won’t points to the updated username value
to fix the problem, you can change
to