Maintain this in a method passed by reference
<p>in the following example, to send as parameter to the method "lostThis" object "instObj", "this" is the window object.</p>

<pre><code>var obj = function() {};
obj.prototype.lostThis = function() {
    console.log('lostThis', this instanceof obj, this);
};

var instObj = new obj;

var caller = {
    runFn: function(fn) {
        fn();
    }
};

caller.runFn(instObj.lostThis);
</code></pre>

<p>Console response:</p>

<pre><code>lostThis false Window
</code></pre>

<p><a href="http://jsfiddle.net/adescalzo/tkQYV/" rel="nofollow">run example</a> </p>

<p>In the following example (slightly more complex) there are different ways to call the methods of "instObj" where it is the same and others where I can keep the "this" object.</p>

<pre><code>var obj = function() {};

obj.prototype.methodRefHasThis = function() {
    var t = this;
    return function() {
        console.log('methodRefHasThis ', t instanceof obj, t);
    };
};

obj.prototype.methodRefLostThis = function() {
    console.log('methodRefLostThis ', this instanceof obj, this);
};

obj.prototype.methodRefMaybeThis = function() {
    console.log('methodRefMaybeThis ', this instanceof obj, this);
};

var instObj = new obj;
var caller = {
    runFn: function(fn) {
        fn();
    }
};

// width jQuery
$('button')
    .bind('click', instObj.methodRefHasThis())
    .bind('click', instObj.methodRefLostThis);

caller.runFn(instObj.methodRefHasThis());
caller.runFn(instObj.methodRefLostThis);
caller.runFn(function() {
    instObj.methodRefMaybeThis();
});​
</code></pre>

<p>Console response:</p>

<pre><code>methodRefHasThis  true obj
methodRefLostThis  false Window
methodRefMaybeThis  true obj

methodRefHasThis  true obj
methodRefLostThis  false &lt;button&gt;​press here​&lt;/button&gt;​
</code></pre>

<p><a href="http://jsfiddle.net/adescalzo/N95Y3/2/" rel="nofollow">run example</a></p>

<p>I understand that this happens with jQuery to assign the method to an event, but <strong>could I call the method "methodRefLostThis" no lose "this" object to be passed by reference?</strong></p>

<p>thanks</p>

<p><strong>Solution by @am_not_i_am , @Dan_Davies_Brackett and @Ben_Lee</strong></p>

<pre><code>var obj = function() {};
obj.prototype.lostThis = function() {
    console.log('lostThis', this instanceof obj, this);
};

var instObj = new obj;

var caller = {
    runFn: function(fn) {
        fn();
    }
};

caller.runFn(instObj.lostThis.bind(instObj));
caller.runFn($.proxy(instObj.lostThis, instObj));
</code></pre>

<p>Console response:</p>

<pre><code>lostThis true obj
lostThis true obj

 ​
</code></pre>

<p><a href="http://jsfiddle.net/adescalzo/7VUGm/" rel="nofollow">run example</a></p>
