Found a solution, thanks to this answer: Backbone View: Inherit and extend events from parent
I added a extraEvents
key to the options of the class, and I changed my events
object to a function that merges the extra events. Code example below, if it helps anyone else:
var MyView = Backbone.View.extend({
el: '#myview',
options: {
extraEvents: {}
},
originalEvents: {
'click .somebutton': 'somefunction',
'click .otherbutton': 'otherfunction'
},
events: function(){
return _.extend({}, this.originalEvents, this.options.extraEvents);
},
somefunction: function(){ console.log('somefunction!'); },
otherfunction: function(){ console.log('otherfunction!'); }
});
Now I can instantiate my view like this:
new MyView({
extraEvents: {
'click .thirdbutton': function(){
console.log('thirdfunction');
}
}
});