title: Revealing Module Pattern with a constructor
body: <p>I'm having a bit of trouble figuring out the best way to implement this.</p>
  
  <p>I want a module that has a constructor that takes in an argument that stores it for later use within the module.</p>
  
  <pre><code>var ModuleB = function(moduleA) {
      this.moduleA = moduleA;
  }
  
  ModuleB.prototype = function() {
      //private stuff/functions
      function someMethod() {
          moduleA.doSomething();
      }
  
      //public api
      return {
          someMethod : someMethod
      };
  }();
  </code></pre>
  
  <p>In some other file</p>
  
  <pre><code>//ModuleA defined elsewhere
  var moduleA = new ModuleA();
  
  //...
  
  var module = new ModuleB(moduleA);
  module.someMethod();
  </code></pre>
  
  <p>Now above in <code>someMethod</code>, moduleA is undefined, and <code>this</code>, is the global window object.  Can someone explain how I would get access to moduleA?  I don't understand what happens to <code>this.moduleA = moduleA;</code> after the constructor.  I'm not really a javascript developer so if I'm using the wrong pattern here or something, feel free to chime in.  </p>