title: how to use the javascript module pattern in a real example?
body: <p>I am trying to understand the JavaScript Module Pattern. I've seen examples of what it should look like, but I don't understand how to use it.</p>
  
  <p>For example, a few things are happening here:</p>
  
  <pre><code>$('input#share').on("click", function() {
  
      $('.loading').html('&lt;img class="remove_loading" src="/graphics/loading.gif" /&gt;');
  
      var message = $(".wallmessage").val();
  
      if (message == ""){
          $("#messageempty").jmNotify();
          $('.remove_loading').remove();
      } else {
          addMessage(message);
      }
  
      return false;
  });
  
  
  function addMessage(message)
  {
      $.ajax({
          url: '/test',
          type: 'POST',
          dataType: "json",
          data: {'message' : message},
          success: function(data) {
                  ...
          },
          error: function() {
              ...
          }
      });
  }
  </code></pre>
  
  <p>How can I use the above example with:</p>
  
  <pre><code>var myTest = function() {
      var selectId;
      function addMessage () {
          // ...
      }
      return { // public interface
          publicMethod1: function () {
              // all private members are accesible here
          }
      };
  };
  var start = myTest();
  </code></pre>
  
  <p>Where do I add the click event, declare my vars, add the <code>addMessage</code> function with the ajax call. and call the <code>addMessage</code> function?  Do i have to wrap everything in <code>$(document).ready(function()</code>?</p>
  
  <p>Can anyone shed some light on this for me?</p>
  
  <p>Thanks</p>