I'm curious how to go about implementing my own sort function on the Array object. Ignoring all the usual warnings/dangers about extending/overriding a built-in, consider this:
Array.prototype.sort = function() {
this = mySortFunction(this);
function mySortFunction(arr) { ... };
};
Inside the closure, this refers to the Array object [number, number2, number3, etc.]. How do I go about reassigning this to be the result of my internal sorting function? Is it possible?
someArray.sort()and notsomeArray = someArray.sort()sortmethod mutates the array, you could make use of it. But I'd say don't do mutation, it's dangerous, counter-intuitive and can be the source of silly bugs, IMO.