Skip to content

Instantly share code, notes, and snippets.

@trcarden
Created May 17, 2012 04:25
Show Gist options
  • Save trcarden/2716346 to your computer and use it in GitHub Desktop.
Save trcarden/2716346 to your computer and use it in GitHub Desktop.
Incorrect Backbone View Advice
// Instead of :
SearchView = Backbone.View.extend({
initialize: function(){
this.render();
},
render: function(){
// Compile the template using underscore
var template = _.template( $("#search_template").html(), {} );
// Load the compiled HTML into the Backbone "el"
this.el.html( template );
}
});
// Write this instead
SearchView = Backbone.View.extend(new function(){
var that = this;
that.initialize = function(){
this.render();
};
that.render = function(){
// Compile the template using underscore
var template = _.template( $("#search_template").html(), {} );
// Load the compiled HTML into the Backbone "el"
this.el.html( template );
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment