Last active
August 29, 2015 14:23
-
-
Save andy-williams/d5baf5d64f88ce28569d to your computer and use it in GitHub Desktop.
Reuse your render method to be standardised
This file contains hidden or 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
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) | |
} | |
})()); |
This file contains hidden or 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
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