Backbone\'s documentation states:
The events property may also be defined as a function that returns an events hash, to make it easier to programmatic
If you are sure that the ParentView
has the events defined as object and you don't need to define events dynamically in ChildView
it is possible to simplify soldier.moth's answer further by getting rid of the function and using _.extend
directly:
var ParentView = Backbone.View.extend({
events: {
'click': 'onclick'
}
});
var ChildView = ParentView.extend({
events: _.extend({}, ParentView.prototype.events, {
'click' : 'onclickChild'
})
});