Skip to content

Instantly share code, notes, and snippets.

@adimasuhid
Created December 8, 2013 03:48
Show Gist options
  • Save adimasuhid/7853146 to your computer and use it in GitHub Desktop.
Save adimasuhid/7853146 to your computer and use it in GitHub Desktop.
Backbone BaseView for handling zombies in large applications
//Backbone Baseview for handling zombies in large applications
//From Backbone Fundamentals by Addy Osmani
var BaseView = function(options){
this.bindings = [];
Backbone.View.apply(this.[options]);
};
_.extend(BaseView.prototype, Backbone.View.prototype, {
bindTo: function(model, ev, callback){
model.bind(ev,callback, this);
this.bindings.push({ model: model, ev: ev, callback: callback})
},
unbindFromAll:function(){
_.each(this.bindings,function(binding){
binding.model.unbind(binding.ev, binding.callback);
});
this.bindings = [];
},
dispose: function(){
this.unbindFromAll();
this.unbind();
this.remove();
}
});
BaseView.extend = Backbone.View.extend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment