Controller.js
var Controller = function(model, view) {
this.self = this;
this.model = model || null;
this.view = view || null;
this.weight = 0;
};
Controller.prototype.init = function(model, view) {
this.model = model;
this.view = view;
};
Controller.prototype.handleEvent = function(e) {
self.weight = parseInt(e.target.value); // !! undefined
e.stopPropagation();
switch (e.type) {
case "click":
self.clickHandler(e.target); // !! undefined
break;
default:
console.log("Not found the event");
}
};
View.js
...
this.btnConvert.addEventListener("click", this.controller.handleEvent);
....
我无法在原型方法中找到如何访问对象本身,即使它是事件处理程序。
不是jQuery,我需要vanilla javascript。
已编辑,已解决
解决方案在评论区域。