Skip to content

Instantly share code, notes, and snippets.

@alexmcpherson
Created January 3, 2013 01:10
Show Gist options
  • Save alexmcpherson/4439963 to your computer and use it in GitHub Desktop.
Save alexmcpherson/4439963 to your computer and use it in GitHub Desktop.
A quick refactor to make the render method idempotent:
var MyView = Backbone.View.extend({
initialize: function() {
//el inserted to the page on init, only called once
$('#content').append(this.el);
this.model.on('change', this.render, this);
},
render: function() {
//.append() changed to .html(), which replaces instead of stacks content
this.$el.html( /* some HTML */ );
}
});
new MyView().render();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment