I have an array of objects i need to sort on a custom function, since i want to do this several times on several object attributes i\'d like to pass the key name for the att
You would need to partially apply the function, e.g. using bind:
arrayOfObjects.sort(compareOn.bind(null, 'myKey'));
Or you just make compareOn return the actual sort function, parametrized with the arguments of the outer function (as demonstrated by the others).
compareOn