title: Javascript Closure vs Javascript OO
body: <p>I was reading <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures" rel="nofollow">Closures</a> and it has the example of the following closure.</p>
  
  <pre><code>var makeCounter = function() {
  var privateCounter = 0;
    function changeBy(val) 
       {
         privateCounter += val;
       }
    return 
       {
         increment: function() 
       {
         changeBy(1);
       },
    decrement: function() 
       {
         changeBy(-1);
       },
    value: function() 
       {
         return privateCounter;
       }
     }
  };
  
  var counter1 = makeCounter();
  var counter2 = makeCounter();
  alert(counter1.value()); /* Alerts 0 */
  counter1.increment();
  counter1.increment();
  alert(counter1.value()); /* Alerts 2 */
  counter1.decrement();
  alert(counter1.value()); /* Alerts 1 */
  alert(counter2.value()); /* Alerts 0 */
  </code></pre>
  
  <p>I was wondering what the difference and advantages/disadvantages are between this closure and the following code that produce the same results.
   <br></p>
  
  <pre><code>var makeCounter = function() {
  var privateCounter = 0;
    function changeBy(val) 
        {
          privateCounter += val;
        };
     this.increment= function() 
       {
         changeBy(1);
       };
     this.decrement= function()
       {
         changeBy(-1);
       };
     this.value= function() 
       {
         return privateCounter;
       };
    };
  
  var counter1 = new makeCounter();
  var counter2 = new makeCounter();
  alert(counter1.value()); /* Alerts 0 */
  counter1.increment();
  counter1.increment();
  alert(counter1.value()); /* Alerts 2 */
  counter1.decrement();
  alert(counter1.value()); /* Alerts 1 */
  alert(counter2.value()); /* Alerts 0 */
  </code></pre>