title: Javascript private methods and private class variables
body: <p>I'm not a professional Javascript dev, so my experience is limited to personal projects using tutorials online as well as trial and error. I've just recently had the need to create an object that has its own methods and member variables etc. I've been reading Doug Crockford notes and others stuff but I'm struggling to understand how it all fits together.  </p>
  
  <p>Consider the following code:</p>
  
  <pre><code>var CLASS_VAR = "some_val";
  
  function MyClass(opts) {
      this.options = opts;
      this.myContainer = null;
  }
  
  MyClass.prototype.doIt = function() {
  
      var privateMethod = function(options) {
          var container = document.createElement("div");
          // use CLASS_VAR and 'options' in some way
          return container;
      }
  
      this.myContainer = privateMethod(this.options);
  }
  </code></pre>
  
  <p>This is essentially the pattern that a portion of my code is using, but I just don't know if it's efficient or proper. Is this pattern a good idea, or are there more sensible/efficient/correct ways of achieving the same thing? In my actual code, there is more than one private function in <code>doIt</code>. Also, there is ~50 "class" variables in the actual code, so should I keep these in the global scope, or is there some way to make them private class variables as in Java <code>private static final</code>?</p>
  
  <p><strong>Edited to reflect first comment</strong></p>