Sub Class a Backbone.View Sub Class & retain events

前端 未结 5 1375
被撕碎了的回忆
被撕碎了的回忆 2020-12-23 17:29

I have a generic subclass of Backbone.View which has a close event listener.

var GenericView = Backbone.View.extend({

    events          


        
5条回答
  •  既然无缘
    2020-12-23 18:12

    Another option is to have a BaseView that overrides the implementation of Extend. Such as:

    var BaseView = Backbone.View.extend({
            //base view functionality if needed
        });
    BaseView.extend = function(child){
        var view = Backbone.View.extend.apply(this, arguments);
        view.prototype.events = _.extend({}, this.prototype.events, child.events);
        return view;
    };
    

    This will automatically extend all of your events for anything that inherits from the BaseView.

提交回复
热议问题