title: How do I access module variables using requireJS?
body: <p>I have been using Javascript for a while and I have just tried using modules and requireJS for the first time and its hard to get my head around new design patterns!</p>
  
  <p>Here is my first attempt:</p>
  
  <pre><code>require([
      "jquery",
      "testModule"
  ], function ($, testModule) {
      $(function () {
          var testInstance1 = testModule;
          testInstance1.setID(11);
          alert(testInstance1.id);
      });
  });
  </code></pre>
  
  <p>and testModule.js</p>
  
  <pre><code>define([
    'jquery'
  ], function ($) {
  
      var id = 0;
  
      var setID = function (newID) {
          id = newID;
          return id;
      };
      return {
          setID: setID,
          id:id
      };
  });
  </code></pre>
  
  <p>This returns 0 and I was expecting 11. What am I missing?</p>
  
  <p>It is also a simplified example of course. I would like to create multiple objects and each should keep its own variables in state. For example if I wanted a module to append a list to a container <code>DIV</code> but also contain functions to add, clear or query data in that list how should I structure the module functions so that each implementation keeps its own state.</p>
  
  <p>Thanks</p>