Customizing the sort functionality of JavaScript arrays
<p>I have this very simple sort method:</p>

<pre><code>sortByNumericAttr : function (a, b,attr){            
        a = a[attr];
        b = b[attr];
        return ((a &lt; b) ? -1 : ((a &gt; b) ? 1 : 0));
}
</code></pre>

<p>the idea here is that I have different objects with different attr that needs sorting (id,type etc.), so i thought instead of writing different sort function for each (where all the difference is only the sorted attribute), I'd write a generic method and pass the attribute to it.</p>

<p>So if it is written like this i can call it like:</p>

<pre><code>arr.sort(utils.sortByNumericAttr,'typeId');
</code></pre>

<p>How can I achieve this or a similar effect, based on this function?</p>
