title: Construct a Javascript object with a complex structure?
body: <p>I have an Object with this structure that I instantiate all around the code</p>
  
  <pre><code>costs: {
      totalPerYear,
      totalEver,
  
      perMonth: {
          items: {
              depreciation,
              insurance,
              credit,
              inspection,
              roadTaxes,
              fuel,
              maintenance,
              repairsImprovements,
              parking,
              tolls,
              fines,
              washing
          },
          standingCosts,
          runningCosts,
          total
      },
  
      perUnitDistance: { 
          runningCosts,
          totalCosts
      }
  }
  </code></pre>
  
  <p>I've been <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects" rel="nofollow noreferrer">reading about constructors</a> and <a href="https://medium.com/dailyjs/instantiation-patterns-in-javascript-8fdcf69e8f9b" rel="nofollow noreferrer">instantiation</a>. Is there a way, for the sake of <em>conciseness</em>, to have a constructor for this object wherein all the variables are set to <code>undefined</code>, like what happens when we define a variable <code>var x;</code>?</p>
  
  <p>I have the obvious solution</p>
  
  <pre><code>function Costs(){
      this.totalPerYear = undefined;
      this.totalEver = undefined;
  
      this.perMonth = {
          items: {
              depreciation: undefined,
              insurance: undefined,
              credit: undefined,
              inspection: undefined,
              roadTaxes: undefined,
              fuel: undefined,
              maintenance: undefined,
              repairsImprovements: undefined,
              parking: undefined,
              tolls: undefined,
              fines: undefined,
              washing: undefined                        
          },
          standingCosts: undefined,
          runningCosts: undefined,
          total: undefined
      };
  
      this.perUnitDistance = { 
          runningCosts: undefined,
          totalCosts: undefined
      };
  };
  
  var userCosts = new Costs();
  </code></pre>
  
  <p>Which techniques do you use to create an object with a complex structure?</p>