Javascript class scope
<p>I am unable to call this.RenderDeals() from inside my Post.success function. I assume this has something to do with scope? Could someone shed some light on the issue, and possibly suggest a workaround. I have tried using prototype and module pattern, both without any luck.</p>

<p>FYI Post is an $.ajax wrapper that returns a jQuery Deferred object.</p>

<pre><code>    function Deals() {
        this.template = '#trTemplate';
        this.container = '#containerTable';
        this.GetDeals = function () {
            Post('Deal.svc/GetDeals')
            .success(function (result) {
                this.RenderDeals(result);
            });
        };
        this.RenderDeals = function (deals) {
            $(this.template).tmpl(deals).appendTo(this.container);
        }
    }


    var deal = new Deals();
    deal.GetDeals();
</code></pre>

<p>UPDATE:</p>

<p>Ok, so I added the following line just above the GetDeals function:</p>

<pre><code>var me = this;
</code></pre>

<p>and instead call</p>

<pre><code>me.RenderDeals(result);
</code></pre>

<p>Appears to work correctly, but I'm not sure why.</p>
