I\'ve watched some videos on the topic of backbone js. This is an example straight from the video. It is from 2012, so I\'m thinking backbone rules/library have changed, but
This can be useful
1: If you have more then one template or sometime you are using external template so it can be useful for you inside method you can write reusable code
var V = Backbone.View.extend({
el:'body',
temp: function (str) {
// reusable code
return _.template(str);
},
render: function () {
var data = { lat: -27, lon: 153 };
// calling your view method temp
var tmpl = this.temp('<%= lat %> <%= lon %>');
this.$el.html(tmpl(data));
return this;
}
});
var v = new V();
v.render();