title: Cannot read property of undefined of function inside loop
body: <p>I have the "error: Cannot read property 'shorten' of undefined" error when running my test. I want my loop to run the shorten function to check if the string is longer then 20 characters, and if so limit it to that.</p>
  
  <pre><code>  function ListView(list) {
      this.list = list;
      this.converted;
    }
  
    ListView.prototype.convert = function() {
      var output = [];
      this.list.notelist.forEach(function(element) {
        this.shorten(element);
        output += "&lt;li&gt;&lt;div&gt;" + element.text + "&lt;/div&gt;&lt;/li&gt;";
      });
      this.converted = "&lt;ul&gt;" + output + "&lt;/ul&gt;";
    };
  
    ListView.prototype.shorten = function(string) {
      if (string.length &gt; 20) {
        return string.substring(0, 20);
      }
      return string;
    };
  </code></pre>
  
  <p>list is from another constructor but i mocked it with;</p>
  
  <pre><code>var mockList = { notelist: [{ text: "hello" }, { text: "goodbye" }] };
  </code></pre>