erik-kallen/SaltarelleCompiler — pull request #372 by sdarnell (2014-12-18 11:02:52+00:00)
Title: Ensure 'this' is the IComparer when the compare callback is called.

Some IComparers need to reference other data or instance methods, but sort() calls the compare callback with a different this value (window on Chrome), so wrap it in a closure.

There seemed to be a couple of similar routines already in mscorlib (ss.thisFix and ss.mkdel) but I couldn't see how to use them directly in this case. So I added a new ss.getComparer(), but I did wonder whether a more general version would be useful.

```
ss.wrapInstanceMethod = function(obj, meth) {
return function() { return meth.apply(obj, arguments); };
};
```
Although this would result in a double reference to {comparer} in the sort case (and thus get lifted).
A less nice version that avoided that, using the method name might be:
```
ss.wrapInstanceMethod = function(obj, methName) {
return function() { return obj[methName].apply(obj, arguments); };
};
```

By the way, I notice that arrays seem to inherit some Sort() methods without Array.cs declaring them. Presumably this is some magic inside the compiler mapping to List ? Or am I missing something obvious. In .Net the Array.Sort() methods are static not instance methods (though in JS it is instance).