I am following a tutorial at: http://arturadib.com/hello-backbonejs/docs/1.html
which has this snippet of code:
(function($){
var ListView = Backbone.View.extend({
el: $('body'), // attaches `this.el` to an existing element.
initialize(): Automatically called upon instantiation. Where you make all types of bindings, excluding UI events, such as clicks, etc.
initialize: function(){
_.bindAll(this, 'render'); // fixes loss of context for 'this' within methods
this.render(); // not all views are self-rendering. This one is.
},
render: function(){
$(this.el).append("<ul> <li>hello world</li> </ul>");
}
});
var listView = new ListView();
})(jQuery);
In the initialize method, why do I need to do bindAll. My understanding of bindAll is that it allows the context of this to be used when render is called.
Since we are calling this.render() isn't the context already this...Why would we need to bindAll?