I have an error: I cannot read the property to “shorten” undefined errors when performing my test. I want my loop to run a shrinking function to check if the string is longer than 20 characters, and if that limits it.
function ListView(list) {
this.list = list;
this.converted;
}
ListView.prototype.convert = function() {
var output = [];
this.list.notelist.forEach(function(element) {
this.shorten(element);
output += "<li><div>" + element.text + "</div></li>";
});
this.converted = "<ul>" + output + "</ul>";
};
ListView.prototype.shorten = function(string) {
if (string.length > 20) {
return string.substring(0, 20);
}
return string;
};
a list from another constructor, but I mocked him:
var mockList = { notelist: [{ text: "hello" }, { text: "goodbye" }] };
source
share