title: Javascript object throwing type error
body: <p>I'm having trouble getting a simple bit of javascript to work. I get this error message:</p>
  
  <pre><code>TypeError: tableKeyPerInd1.getTotal is not a function
  tempHold = tableKeyPerInd1.getTotal();
  </code></pre>
  
  <p>From this code:</p>
  
  <pre><code> tableKeyPerInd1 = new table("keyPerformanceIndicators");
   console.log(tableKeyPerInd1.table);
   tempHold = tableKeyPerInd1.getTotal();
   console.log(tempHold);
   function table(TableName){
  
    this.table=TableName;
  
    function getTotal()
    {
     this.runningTotal = 0;
     columns = new Array("Mon","Tue","Wed","Thu","Fri","Sat");
     for(var t=0; t&lt;columns.length ;t+=1){
      this.runningTotal += $('SupplementaryExamKPI'+columns[t]) + $('DiabeticScreeningKPI'+columns[t])+$('LvaKPI'+columns[t]);
     }
    }
   }
  </code></pre>
  
  <p>How can I fix this?</p>
  
  <hr>
  
  <p>I thought it might help others if I posted the complete solution.  I've also added into this solution how to create objects on the fly.  So this creates a total and it creates individual objects for each day  i.e this.Mon, this.Tue etc</p>
  
  <pre><code> tableKeyPerInd1 = new table("keyPerformanceIndicators");
   columns = new Array("Mon","Tue","Wed","Thu","Fri","Sat");
  
   function table(TableName){
  
    this.table=TableName;
    this.runningTotal = 0;
    this.Mon = 0;
    this.getTotal =   function getTotal()
    {
     this.runningTotal = 0;
  
     for(var t=0; t&lt;columns.length ;t+=1){
      var supexam = Number.from($('SupplementaryExamKPI'+columns[t]).get('value'));
      var diabeticscreen = Number.from($('DiabeticScreeningKPI'+columns[t]).get('value'));
      var lva = Number.from($('LvaKPI'+columns[t]).get('value'));
      this.runningTotal += supexam + diabeticscreen+lva;
      this[columns[t]] = supexam + diabeticscreen+lva;
     }
     return ;
    }
   }
  </code></pre>