I'm having trouble getting my function to increment user id on the creation of every new object, but also preventing other functions from changing it.
function User(u_name) {
this.user_name = u_name;
this.user_id = User.next_user_id++;
}
User.next_user_id = 1;
user1 = new User('john');
user2 = new User('jane');
if I move next_user_id into function User as var next_user_id
then it gets reset on every new object, which is not what I want.
How can I increment user_id for every new object but prevent other functions from changing it?