Backbone View: Inherit and extend events from parent

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

    This CoffeeScript solution worked for me (and takes into account @soldier.moth's suggestion):

    class ParentView extends Backbone.View
      events: ->
        'foo' : 'doSomething'
    
    class ChildView extends ParentView
      events: ->
        _.extend({}, _.result(ParentView.prototype, 'events') || {},
          'bar' : 'doOtherThing')
    

提交回复
热议问题