title: Setting variable through external method in method of object
body: <p>I am using the method of a javascript object to create HTML to write that object. 
  Within that method I have a date (in string format as a SQL Date) which I format to dd MMM YYYY in an external method. The external method works fine returning the string I need, but when I set the variable within my object's method it is returned as <code>undefined</code>.</p>
  
  <p>Hereby the relevant code:</p>
  
  <pre><code>function CreateReview(reviewID, visitDate) {
      var reviewObject = {
          iD: reviewID,
          visitDate: visitDate, 
          CreateReviewObject : function(c) {
              var reviewContainer = document.createElement('div');
              reviewContainer.id = 'Review_' + this.iD;
              reviewContainer.className  = 'Card Review';
              var headerDIV = document.createElement('div');
              headerDIV.className  = 'Header';
              var dateTagsDIV = document.createElement('div');
              dateTagsDIV.className  = 'DateTags';
              var datesDIV = document.createElement('div');
              datesDIV.className  = 'Dates';
              var formattedVisitDate = getFormattedDate(this.visitDate);
              console.log(formattedVisitDate);
              var dateDIV = document.createElement('div');
              dateDIV.className  = 'Date';
              dateDIV.innerHTML = formattedVisitDate;
              datesDIV.appendChild(dateDIV);
              dateTagsDIV.appendChild(datesDIV);
              headerDIV.appendChild(dateTagsDIV);
              reviewContainer.appendChild(headerDIV);
  
              return reviewContainer;
          }
      };
  
      return reviewObject;
  }
  
  function getFormattedDate(input) {
      input = input.replace(/-/g,'/');
      var pattern = /(.*?)\/(.*?)\/(.*?)$/;
      var result = input.replace(pattern,function(match,p1,p2,p3){
          p2 = parseInt(p2);
          p3 = parseInt(p3);
          var months = ['jan','feb','maa','apr','mei','jun','jul','aug','sep','okt','nov','dec'];
          var date = (p3&lt;10?"0"+p3:p3) + " " + months[parseInt(p2-1)] + " " + p1;
          console.log(date);
          return date;
  
      });
  }
  </code></pre>
  
  <p>The output of the console in <code>getFormattedDate</code> is then </p>
  
  <pre><code>12 mei 2015
  </code></pre>
  
  <p>While in <code>CreateReview</code> it is</p>
  
  <pre><code>undefined
  </code></pre>
  
  <p>I have tried the following way as well:</p>
  
  <pre><code>function CreateReview(reviewID, restaurant, kitchenTypes, tags, pictures, ratings, thumbPicture, visitDate, introduction, description) {
      var reviewObject = {
          iD: reviewID,
          visitDate: visitDate, 
          CreateReviewObject : function(c) {
              var getFormattedVisitDate = function(visitDate) {
                return function() { getFormattedDate(visitDate); };
              };
              var reviewContainer = document.createElement('div');
              reviewContainer.id = 'Review_' + this.iD;
              reviewContainer.className  = 'Card Review';
              var headerDIV = document.createElement('div');
              headerDIV.className  = 'Header';
              var dateTagsDIV = document.createElement('div');
              dateTagsDIV.className  = 'DateTags';
              var datesDIV = document.createElement('div');
              datesDIV.className  = 'Dates';
              var formattedVisitDate = getFormattedVisitDate(this.visitDate);
              console.log(formattedVisitDate);
              var dateDIV = document.createElement('div');
              dateDIV.className  = 'Date';
              dateDIV.innerHTML = formattedVisitDate;
              datesDIV.appendChild(dateDIV);
              dateTagsDIV.appendChild(datesDIV);
              headerDIV.appendChild(dateTagsDIV);
              reviewContainer.appendChild(headerDIV);
  
              return reviewContainer;
          }
      };
  
      return reviewObject;
  }
  
  function getFormattedDate(input) {
      input = input.replace(/-/g,'/');
      var pattern = /(.*?)\/(.*?)\/(.*?)$/;
      var result = input.replace(pattern,function(match,p1,p2,p3){
          p2 = parseInt(p2);
          p3 = parseInt(p3);
          var months = ['jan','feb','maa','apr','mei','jun','jul','aug','sep','okt','nov','dec'];
          var date = (p3&lt;10?"0"+p3:p3) + " " + months[parseInt(p2-1)] + " " + p1;
          console.log(date);
          return date;
  
      });
  }
  </code></pre>
  
  <p>Which gives me this output in  in <code>CreateReview</code>:</p>
  
  <pre><code>return function() { getFormattedDate(visitDate); };
  </code></pre>
  
  <p>Why does the <code>CreateReview</code> call return <code>undefined</code> when the console does not?</p>