I do not believe jQuery has a sort function at all. JavaScript does, on arrays . jQuery and JavaScript are two different things (one is a library, the other is a language). Update : Ah, jQuery has an undocumented sort (one of several functions that it takes from Array.prototype ), but this fact is not documented and therefore can change from point to point release. Thanks, Felix .
You cannot pass the third argument to a function directly. You can pass the function you pass to sort to call another function:
// ...assuming `desc` is in scope here here... obj.sort(function(a, b) { return StringSort(a, b, desc); });
The same desc will be passed to StringSort for each pair of compared records. a and b , of course, will be different for every call.
This works because the function we pass to sort is a closure in the context in which desc defined. This means that a function can access desc (just as functions can access global variables for the same reason).
More on closing:
source share