Tuesday, 15 June 2010

javascript - Backbone and underscore js why do I need to use bindAll -



javascript - Backbone and underscore js why do I need to use bindAll -

i next tutorial at: http://arturadib.com/hello-backbonejs/docs/1.html

which has snippet of code:

(function($){ var listview = backbone.view.extend({ el: $('body'), // attaches `this.el` existing element. initialize(): automatically called upon instantiation. create types of bindings, excluding ui events, such clicks, etc. initialize: function(){ _.bindall(this, 'render'); // fixes loss of context 'this' within methods this.render(); // not views self-rendering. 1 is. }, render: function(){ $(this.el).append("<ul> <li>hello world</li> </ul>"); } }); var listview = new listview(); })(jquery);

in initialize method, why need bindall. understanding of bindall allows context of used when render called.

since calling this.render() isn't context this...why need bindall?

in code, bindall 'render' indeed redundant. it's useful when render called in other context(esp. callback).

javascript backbone.js underscore.js

No comments:

Post a Comment