我有带有原型方法的简单javascript“类”,但是在方法itemDelete()
中,我收到了错误消息this.save is not a function
。我认为是因为有jquery监听器,但是我不知道如何解决这个问题。
function Manager(el, type) {
this.el = el;
this.type = type;
this.render();
}
Manager.prototype.render = function() {
// render stuff
};
Manager.prototype.itemAdd = function(item) {
var element = $('#' + this.el).html(item);
element.on('click', this.itemDelete);
}
Manager.prototype.itemDelete = function(event) {
$('#' + event.target).remove();
this.save('itemDelete');
}
Manager.prototype.save = function(method) {
// save stuff
}