jQuery bind with a different this

javascript, jquery

Solution

You can use jQuery.proxy:

$('#selector').bind('click', $.proxy(this.foo,this) );

Problem

I want to bind a function to an event but I want to change the context in which the function is called ``` function Foo(){ t : "123", bar: function(){ // I am here $('#selector').bind('click' this.foo); } , foo: function(){ //I want when to be able to use the current object here by this //this.t should be 123 and this.bar should call the above function } } ```

Original source