Backbone View Inheritance

前端 未结 4 1944
猫巷女王i
猫巷女王i 2021-01-12 20:33

I am trying to write a Backbone view for an object browser which is designed to be implemented in several places with different object types and slightly different operation

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-12 21:20

    Inherit from Backbone.View doesn't work, or is quite complex.

    You should create a common object, which every of your view will inherit from, ie :

    var ViewInterface = {
      events        : { /* ... */ },
      initialize    : function (options) { /* ... */ },
      otherFunction : function (options) { /* ... */ },
    }
    

    each of your view would extend from this object :

    var BrowserView = Backbone.View.extend(_.extend(ViewInterface, {
      anotherFunction : function (options) { /* ... */ },
    })
    
    var AnotherView = Backbone.View.extend(_.extend(ViewInterface, {
      yetAnotherFunction : function (options) { /* ... */ },
    })
    

提交回复
热议问题