title: How to call self executing function from another file
body: <p>I'm studying the object oriented features of Javascript and I'm looking at the "Module Pattern". I have a self executing function, which I'd like to call from another file but I keep getting errors. </p>
  
  <p>Here's the self executing module: </p>
  
  <pre><code>var basketModule = (function () {
      var basket = [];
      function doSomethingPrivate() {
        //...
      }
      // Return an object exposed to the public
      return {
        // Add items to our basket
        addItem: function( values ) {
            basket.push(values);
        },
        // Get the count of items in the basket
        getItemCount: function () {
            return basket.length;
        }, 
     };
  })();
  </code></pre>
  
  <p>I'm trying to use this from another file called <code>Run.js</code>:</p>
  
  <pre><code>var basketModule = require("./basketModule");
  
  basketModule.addItem({
    item: "bread",
    price: 0.5
  });
  console.log( basketModule.getItemCount() );
  </code></pre>
  
  <p>When I run this <code>node Run.js</code> I get an error: </p>
  
  <blockquote>
    <p>basketModule.addItem is not a function. </p>
  </blockquote>
  
  <p>I tried adding a call to basketModule like this: <code>basketModule();</code> immediately after the require but this results in </p>
  
  <blockquote>
    <p>TypeError: basketModule is not a function.</p>
  </blockquote>
  
  <p>What am I missing? </p>
  
  <pre><code>console.log( basketModule.getItemCount());
  </code></pre>