Backbone View: Inherit and extend events from parent

前端 未结 15 762
醉梦人生
醉梦人生 2020-11-30 16:50

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

15条回答
  •  隐瞒了意图╮
    2020-11-30 17:40

    The soldier.moth answer is a good one. Simplifying it further you could just do the following

    var ChildView = ParentView.extend({
       initialize: function(){
           _.extend(this.events, ParentView.prototype.events);
       }
    });
    

    Then just define your events in either class in the typical way.

提交回复
热议问题