javascript - How to reuse render function for multiple views in Backbone? -


i'm working on app in backbone, , have multiple views have same render function:

render: function(){     this.$el.html(this.template(this.model.tojson()));     return this; } 

how reuse function in multiple views can follow old dry way?

you can use mixin pattern specified here: proper way of doing view mixins in backbone

var renderable = {     render: function(){         this.$el.html(this.template(this.model.tojson()));         return this;     } };  var view = backbone.view.extend({ //other methods });  _.extend(view.prototype, renderable);  var myview = new view(); myview.render(); 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -