es6.array.sort.js 643 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. var $export = require('./_export');
  3. var aFunction = require('./_a-function');
  4. var toObject = require('./_to-object');
  5. var fails = require('./_fails');
  6. var $sort = [].sort;
  7. var test = [1, 2, 3];
  8. $export($export.P + $export.F * (fails(function () {
  9. // IE8-
  10. test.sort(undefined);
  11. }) || !fails(function () {
  12. // V8 bug
  13. test.sort(null);
  14. // Old WebKit
  15. }) || !require('./_strict-method')($sort)), 'Array', {
  16. // 22.1.3.25 Array.prototype.sort(comparefn)
  17. sort: function sort(comparefn) {
  18. return comparefn === undefined
  19. ? $sort.call(toObject(this))
  20. : $sort.call(toObject(this), aFunction(comparefn));
  21. }
  22. });