title: Implementing private instance variables in Javascript
body: <p>I don't know how I've missed this for so long. I've been presuming private instance variables to work like this, but they don't. They're private (as in non-global), certainly, but the variables are shared across instances. This led to some very confusing bugs.</p>
  
  <p>I thought I was following the best practices implemented by some of the best libraries out there, but it seems I missed something.</p>
  
  <pre><code>var Printer = (function(){
      var _word;
  
      Printer = function(word){
          _word = word;
      }
  
      _print = function(){
          console.log(_word);
      }
  
      Printer.prototype = {
          print: _print
      }
      return Printer;
  })();
  
  var a = new Printer("Alex");
  var b = new Printer("Bob");
  
  a.print(); //Prints Bob (!)
  b.print(); //Prints Bob
  </code></pre>
  
  <p>I have looked at this post, but it doesn't describe a best practice for implementing private instance variables. (is this even the name of what I want?)
  <a href="https://stackoverflow.com/questions/5099519/method-and-variable-scoping-of-private-and-instance-variables-in-javascript">Method and variable scoping of private and instance variables in JavaScript</a></p>
  
  <p>I also looked at this post, but the use of the 'this' keyword is what I used to do. Because it doesn't obfuscate I was trying to avoid it. Is this really the only way?
  <a href="https://stackoverflow.com/questions/2107776/implementing-instance-methods-variables-in-prototypal-inheritance">Implementing instance methods/variables in prototypal inheritance</a></p>