Backbone View: Inherit and extend events from parent

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

    If you use CoffeeScript and set a function to events, you can use super.

    class ParentView extends Backbone.View
      events: ->
        'foo' : 'doSomething'
    
    class ChildView extends ParentView
      events: ->
        _.extend {}, super,
          'bar' : 'doOtherThing'
    

提交回复
热议问题