I am using backbone.js here is my scenario
Lets say I have a view called FooView
class FooView extends Backbone.view
initialize:->
$('#manage-foo').bind('click', @render)
render: ->
//whatever I want to render
I want to bind the click on the element #manage-foo to render my view or to call a function of my view FooView but I do not want to loose context in which the function is called, the function render should be called with this pointing to the FooView rather than the element How do I achieve this. ?
The case that I have is that I create the FooView on pageLoad and I have to show it when a give element is clicked
Thanks
Not sure if this answers your question 100% but
_.bindAll(this, 'render');fixes the loss of context. You can add all of the methods for which you need to do this with, so you can_.bindAll(this, 'render,click');and add a click method.http://arturadib.com/hello-backbonejs/docs/1.html