"I'm having trouble understanding a piece of my code:
//constructor
function Widget (options) {
};
//return the string
Widget.prototype._addEditFormString = function (val) {
return "<input type='text' value='" + val + "' >";
}
//initializing method
Widget.prototype.init = function () {
var addRowButton = document.getElementsByName("addRow")[0];
addRowButton.addEventListener("click", this.addRow, false);
};
//this context in this method is still confusing me
Widget.prototype.addRow = function () {
console.log(this._addEditFormString);//Uncaught TypeError: Object #<HTMLInputElement> has no method '_addEditFormString'
}
var wid = new Widget();
wid.init();
The issue - In the init() method I add an event listener (addRow method), but in the addRow method, I am unsure how to reference "this" of my constructor class. I want to invoke _addEditFormString() method, but I receive "Uncaught TypeError: Object [object Window] has no method '_addEditFormString'". How can I solve this without using Widget.prototype._addEditFormString? Is that the only solution? Thank you.