I have an object containing both public and private variables. The public variables are assigned to the private variables (I think), however, whenever I modify the private variables with a function, the public variables don't update.
var foo = (function() {
    //Private vars
    var a = 1;
    return {
        //Public vars/methods
        a: a,
        changeVar: function () {
            a = 2;
        }
    }
})();
alert(foo.a);  //result: 1
foo.changeVar();
alert(foo.a);  //result: 1, I want it to be 2 though
Now I know that if I change the line in changeVar to this.a = 2; it works but then it doesn't update the private variable. I want to update both the private and public variables at the same time. Is this possible?
 
     
     
    