title: JavaScript Object instantiation within another Object methods
body: <p>I'm trying to figure out how to handle the situation, where you have several objects under the same namespace, where methods of all of them might be used interchangeably - i.e. first object might be using methods from the second one and the second one from the first. Both might also use other objects etc. It's best to represent it with an example:</p>
  
  <pre><code>var MySystem = MySystem || {};
  
  MySystem.Form = function() {};
  
  MySystem.Form.prototype = {
  
      objErrorHandler : null,
      objHelper : null,
      objValidation : null,
  
      idClickSubmit : '.submitClick',
  
      getAttributes : function(thisForm) {
  
          "use strict";
  
          if (this.objValidation.isEmpty(thisForm)) {
  
              return {};
  
          }
  
      },
  
      submit : function() {
  
          "use strict";
  
          var self = this;
  
          $(document).on(
              'click',
              self.idClickSubmit,
              self.objErrorHandler.tryCatch(function(event) {
  
                  self.objHelper.preventDefaultPropagation(event);
  
                  var thisTarget = $(this).data('target');
  
                  $('form[data-identity="' + thisTarget + '"]').submit();
  
              })
          );
  
      },
  
      dynamicRow : function() {
  
          "use strict";
  
          var objFormDynamicRow = new MySystem.FormDynamicRow();
          objFormDynamicRow.init();
  
      },
  
      init : function() {
  
          "use strict";
  
          var self = this;
  
          self.objErrorHandler = new CMDSystem.ErrorHandler();
          self.objHelper = new CMDSystem.Helper();
          self.objValidation = new CMDSystem.Validation();
  
          self.objErrorHandler.tryCatch(function() {
  
              self.submit();
              self.dynamicRow();
  
          })(self);
  
      }
  
  };
  </code></pre>
  
  <p>Now - to instantiate this object I would use:</p>
  
  <pre><code>var objForm = new MySystem.Form();
  objForm.init();
  </code></pre>
  
  <p>The problem is that Validation object might make use of the getAttributes() method of the Form object and I would either instantiate it within Validation.init() method or within the method that would be calling it.</p>
  
  <p>Now, the question here is - would I be better instantiating all additional objects (ErrorHandler, Helper and Validation) within each method that requires it (as private objects) or is the above approach correct and what are the benefits / drawbacks of using either approach.</p>