This is part of a program that was built in attempt to use the Model-View-Controller design pattern. As I understand it, I cannot use the this keyword itself in the function handling a click event. But when I use _this instead, I got the error : Uncaught TypeError: _this.saveCastle is not a function.
Also, when I used console.log on _this, it returned the global object and I had believed it should point to the local function.
Any feedback is appreciated, thanks.
var CreateCastleView = (function () {
function CreateCastleView(document, controller, model, validationResult) {
this.document = document;
this.controller = controller;
this.model = model;
this.validationResult = validationResult;
var _this = this;
this.document.getElementById('save').addEventListener('click', function() {
return _this.saveCastle();
});
CreateCastleView.prototype.saveCastle = function() {
console.log("This isn't being called");
};
return CreateCastleView;
})();
CreateCastleViewand where are you trying to construct it?thisyou are getting is before thesaveCastlemethod is attached.