Created
December 8, 2013 03:48
-
-
Save adimasuhid/7853146 to your computer and use it in GitHub Desktop.
Backbone BaseView for handling zombies in large applications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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