Created
May 17, 2012 04:25
-
-
Save trcarden/2716346 to your computer and use it in GitHub Desktop.
Incorrect Backbone View Advice
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
// 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