I have this very simple sort method:
sortByNumericAttr : function (a, b,attr){
a = a[attr];
b = b[attr];
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
}
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.
So if it is written like this i can call it like:
arr.sort(utils.sortByNumericAttr,'typeId');
How can I achieve this or a similar effect, based on this function?