title: Initiating and saving JavaScript object to a variable
body: <p>How can I save/reuse objects in JavaScript? </p>
  
  <pre><code>if (typeof window.Test == "undefined") window.Test = {};
  if (typeof Test == "undefined") Test = {};
  
  Test.Object1 = function() {
      var obj =  {
  
          init: function(msg) {
              console.log(msg);
          },
  
          EOF: null
      };
  
      return obj;
  }();
  
  Test.Test = function() {
      var obj = {
  
          init: function() {
              var obj1 = Test.Object1.init('Object 1 initialized');
              console.log(obj1);
          },
  
          EOF: null
      };
  
      return obj;
  }();
  
  Test.Test.init();
  </code></pre>
  
  <p><code>console.log(obj1)</code> returns <code>undefined</code></p>
  
  <p><code>var obj1 = new Test.Object1();</code> produces <code>TypeError: Test.Object1 is not a constructor</code></p>