Javascript array sort Method problem?

JavaScript is a bit weird. When you make a new function, this refers to that function, not your hero any more. So you can do something like this instead:

var self = this;
function sortFunction(a, b) {
    return a.distanceTo(self) - b.distanceTo(self);
}
2 Likes