I apologise for such a simple question - I'm new to JS, though I thought I understand this pattern (combination constructor/prototype).
In my code (snippet below), my prototype methods for my "Journal" type cannot read instance properties of objects of journal type. But my other types work fine, and I can't see the difference between my journal type and my other types.
Clicking on my save button (invoking updateEntry method, code below) gives me this error:
Uncaught TypeError: Cannot read property 'length' of undefined
Here is the relevant JavaScript -
var Journal = function(saveBtn) {
this.entries = [];
this.saveBtn = document.getElementById(saveBtn);
this.saveBtn.onclick = this.updateEntry;
};
Journal.prototype.updateEntry = function() {
console.log('Let\'s see if entries accessible: ' + this.entries.length);
};
var journal = new Journal('btn');
Why can journal's invocation of Journal.prototype.updateEntry() not view journal.entries?