title: Javascript revealing module pattern, public properties
body: <p>I'm trying to get my head round the revealing module pattern in javascript. I'm puzzled by two things about the following code snippet.</p>
  
  <pre><code>        var Child = function () {
              var totalPoints = 100;
              addPoints = function (points) {
                  totalPoints += points;
                  return totalPoints;
              };
              getPoints = function () {
                  return totalPoints;
              };
              return {
                  points: totalPoints,
                  addPoints: addPoints
              };
          };
          $(function () {
              var george = Child();
              console.log(george.points);
              console.log(george.addPoints(50));
              console.log(george.points);
          });
  </code></pre>
  
  <ol>
  <li><p>The three values written to the console here are 100, 150, 100. That tells me that when I call "addPoints" with a value the totalPoints variable isn't updated. If I examine the value of totalPoints <em>within</em> the addPoints function it <em>has</em> been incremented properly. <strong>What's going on?</strong></p></li>
  <li><p>If I use the console to examine window.addPoints or window.getPoints I can see that because I haven't used "var" in front of the function declarations they've been added to the global scope. <strong>Isn't that wrong?</strong> Most of the examples I'm looking at seem to do this.</p></li>
  </ol>
  
  <p>Any pointers gratefully received.</p>