I have this object:
var eventDisplay = {
eventTable: $('.table-event > table'),
archiveButton: $('table-event__archive-button'),
deleteButton: $('table-event__delete-button'),
checkedCheckboxes: $('.table-event input[type=checkbox]'),
countChecked: function() {
return this.checkboxes.filter(':checked').length;
},
selectionChanged: function() {
if (this.countChecked() > 0) {
deleteButton.removeClass("disabled");
archiveButton.removeClass("disabled");
} else {
deleteButton.addClass("disabled");
archiveButton.addClass("disabled");
}
},
attachCheckboxHandler: function() {
this.checkboxes.on('click', this.selectionChanged);
}
}
When I call eventDisplay.attachCheckboxHandler()
, the this
in attachCheckboxHandler is refering to the object as I expected. However, as it calls selectionChanged
, this
refers to the checkbox instead. But I want this
within the selectionChanged to refer to eventDisplay
. Is it possible to do that? If so, how?