Skip to content

Instantly share code, notes, and snippets.

@andy-williams
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andy-williams/d5baf5d64f88ce28569d to your computer and use it in GitHub Desktop.
Save andy-williams/d5baf5d64f88ce28569d to your computer and use it in GitHub Desktop.
Reuse your render method to be standardised
myNameSpace.backboneExtensions.methods.render = function() {
this.$el.html(this.tmpl(this.model.attributes));
return this;
}
MyView = Backbone.View((function() {
var myRender = myNameSpace.backboneExtensions.methods.render;
return {
// your properties
// render
render: this.call(myRender)
}
})());
MyApp.BackBone.View = Backbone.View.extend({
render: function() {
this.$el.html(this.tmpl(this.model.attributes));
return this;
}
});
ExampleView = MyApp.BackBone.View.extend({
el: 'li'
}); // this Backbone view's render method automatically renders whatever is in the template
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment