Backbone View: Inherit and extend events from parent

前端 未结 15 732
醉梦人生
醉梦人生 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:30

    Short version of @soldier.moth's last suggestion:

    var ChildView = ParentView.extend({
      events: function(){
        return _.extend({}, _.result(ParentView.prototype, 'events') || {}, {
          'click' : 'onclickChild'
        });
      }
    });
    

提交回复
热议问题