Javascript setting object property inside object callback
<p>I am trying to set an object (summary) inside another object's callback method</p>

<pre><code>returnObj.beforeLoadComplete = function (records) {
    var someObj = {
        total: {
            label: 'Items',
            value: '15'
        },
        additional: [{
            label: 'Item1 Total',
            value: '25000'
        }]
    };

    returnObj.summary = summaryObj;
    // some other code which finally returns an object
}
</code></pre>

<p>The above code does not work (i.e. <code>summary</code> is not set on <code>returnObj</code>)</p>

<p>However if I have the same code outside the callback method, it works as in code snippet below:</p>

<pre><code>var someObj = {
    total: {
        label: 'Items',
        value: '15'
    },
    additional: [{
        label: 'Item1 Total',
        value: '25000'
    }]
};

returnObj.summary = summaryObj;
returnObj.beforeLoadComplete = function (records) {
    // some other code which finally returns an object
}
</code></pre>

<p>Not sure why is it so.</p>