Skip to content

Instantly share code, notes, and snippets.

@phawk
Created December 9, 2012 20:10
Show Gist options
  • Save phawk/4246777 to your computer and use it in GitHub Desktop.
Save phawk/4246777 to your computer and use it in GitHub Desktop.
var app = app || { views: {} };
app.views.MyView = Backbone.View.extend({
initialize: function() {
app.events.bind("some-event", this.render, this);
},
events: {
"click .reload": "render"
},
render: function() {
this.$el.html(this.template(this.model.toJSON()));
},
destroy: function() {
// Unbind the custom events
app.events.unbind("some-event", this.render);
}
});
var myView = new app.views.MyView();
// Cleanup the view safely
myView.destroy();
myView.remove();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment