title: Javascript Public/Private Variables
body: <p>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.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Now I know that if I change the line in changeVar to <code>this.a = 2;</code> 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?</p>
  
  <p><a href="http://jsfiddle.net/H55qy/" rel="nofollow">JsFiddle showing problem</a></p>