title: JavaScript Classes
body: <p>I understand basic JavaScript pseudo-classes:</p>
  
  <pre><code>function Foo(bar) {
      this._bar = bar;
  }
  
  Foo.prototype.getBar = function() {
      return this._bar;
  };
  
  var foo = new Foo('bar');
  alert(foo.getBar()); // 'bar'
  alert(foo._bar); // 'bar'
  </code></pre>
  
  <p>I also understand the module pattern, which can emulate encapsulation:</p>
  
  <pre><code>var Foo = (function() {
      var _bar;
  
      return {
          getBar: function() {
              return _bar;
          },
          setBar: function(bar) {
              _bar = bar;
          }
      };
  })();
  
  Foo.setBar('bar');
  alert(Foo.getBar()); // 'bar'
  alert(Foo._bar); // undefined
  </code></pre>
  
  <p>But there are un-OOP-like properties to both of these patterns.  The former does not provide encapsulation.  The latter does not provide instantiation.  Both patterns can be modified to support pseudo-inheritance.</p>
  
  <p>What I'd like to know is if there is any pattern that allows:</p>
  
  <ul>
  <li>Inheritance</li>
  <li>Encapsulation (support for "private" properties/methods)</li>
  <li>Instantiation (can have multiple instances of the "class", each with its own state)</li>
  </ul>