_.bindAll( this, ... ) needed not only for this.$( selector ).doSomething() , but in general, to make sure that this in your view method always points to the view itself.
For example, if we want to update our view when the model changes, we bind the view render method to the change model event:
initialize: function() { this.model.bind( 'change', this.render ); },
Without _.bindAll( this, 'render' ) , when changing the this model to render will point to the model, and not to the view, so we will have neither this.el , nor this.$ , Or any other properties of the view available.
Georgii Ivankin Jun 18 2018-11-11T00: 00Z
source share