Very confused about JavaScript scopes
<p>Below is a greatly simplified snippet of code derived from a SlickGrid sample:</p>

<p><strong>model.js:</strong></p>

<pre><code>(function($) {
    function RemoteModel() {
        var someArr=[0];
        var someVar=0;
        var onDataLoadedSuccess = new Slick.Event();

        function ensureData(from, to) {
            h_request = setTimeout(function() {
                req = $.ajax({
                    url: url,
                    context: this,
                    success: function(resp) {
                        onSuccess();
                    }
                });
            }, 3000);
        }

        function onSuccess() {
            someVar=someVar+100;
            someArr[0]=someArr[0]+100;
            console.log(someVar + " " + someArr[0]); // yes values are changing properly for both !

            onDataLoadedSuccess.notify({ from: from, to: to });
        }

        return {
            "someArr": someArr,
            "someVar": someVar,
            "onDataLoadedSuccess": onDataLoadedSuccess,
        };
    }
})(jQuery);
</code></pre>

<p><strong>main.js:</strong></p>

<pre><code>var loader=new RemoteModel();
var grid=new Slick.Grid("#wlGrid", loader.data, columns, options);

grid.onViewportChanged.subscribe(function(e, args) {
    var vp = grid.getViewport();
    loader.ensureData(vp.top, vp.bottom);
});

loader.onDataLoadedSuccess.subscribe(function(e, args) {
    // someVar is always 0 :( ! someArr[0] is changing fine .. why ???
    console.log(loader.someVar + " " + loader.someArr[0]); 
});
</code></pre>

<p>So an event on the grid (<code>onViewportChanged</code>) is calling <code>ensureData</code> on the model, which 
increments both <code>someVar</code> and <code>someArr[0]</code>, both of which are exposed by the return value 
of <code>RemoteModel</code>.</p>

<p>After incrementing the event, <code>onDataLoadedSuccess</code> is triggered by the model, however 
within that event only the value of <code>loader.someArr[0]</code> has changed. </p>

<p>why is the value of <code>someVar</code> in <code>onDataLoadedSuccess</code> always zero? Is that a scope issue?
And why is the value of <code>someArr[0]</code> changing fine?</p>

<p>How can I properly read the value of <code>someVar</code> in <code>onDataLoadedSuccess</code>?</p>
