Skip to content

Instantly share code, notes, and snippets.

@sagar-ganatra
Created January 25, 2013 05:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sagar-ganatra/4632091 to your computer and use it in GitHub Desktop.
Save sagar-ganatra/4632091 to your computer and use it in GitHub Desktop.
Adding beforeRender and afterRender functions to a Backbone View Refer to the blog post http://www.sagarganatra.com/2013/01/adding-beforerender-and-afterrender-functions-to-backbone-view.html
(function () {
var TestView = Backbone.View.extend({
el: '#container',
initialize: function () {
console.log('Inside Init');
this.render = _.wrap(this.render, function(render) {
this.beforeRender();
render();
this.afterRender();
});
this.render();
},
render: function () {
console.log('Inside render');
return this;
},
beforeRender: function () {
console.log("Before render");
},
afterRender: function () {
console.log("After render");
}
});
var testViewInstance = new TestView;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment