title: Calling public method within module javascript
body: <p>I'm trying to call a public method from within the module pattern.</p>
  
  <p>I'm using the module pattern because it allows for splitting into various different JS files, to make the code more organised.</p>
  
  <p>However when I call the public method, I get a <code>TypeError</code> and also <code>typeof</code> remains undefined.</p>
  
  <p>Please help!! Thanks in advance.</p>
  
  <h3>main.js</h3>
  
  <pre><code>function MainObject() {
      this.notify = function(msg) { console.log(msg); }
  }
  
  var connObj = require("./myextobj");
  
  var mainObj = new MainObject();
  
  connObj.connection.handle = mainObj;
  
  console.log(typeof connObj.connection.connect); // undefined
  
  connObj.connection.connect(); // TypeError: Object has no method 'connect'
  </code></pre>
  
  <h3>myextobj.js</h3>
  
  <pre><code>module.exports = {
  
      connection: function () {
  
          this.handle = eventhandle;
  
          this.connect = function() {
  
              // connect to server
              handle.notify("completed connection....");
  
          }
      }   
  }
  </code></pre>