es.array.find.js 874 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var $find = require('../internals/array-iteration').find;
  4. var addToUnscopables = require('../internals/add-to-unscopables');
  5. var arrayMethodUsesToLength = require('../internals/array-method-uses-to-length');
  6. var FIND = 'find';
  7. var SKIPS_HOLES = true;
  8. var USES_TO_LENGTH = arrayMethodUsesToLength(FIND);
  9. // Shouldn't skip holes
  10. if (FIND in []) Array(1)[FIND](function () { SKIPS_HOLES = false; });
  11. // `Array.prototype.find` method
  12. // https://tc39.github.io/ecma262/#sec-array.prototype.find
  13. $({ target: 'Array', proto: true, forced: SKIPS_HOLES || !USES_TO_LENGTH }, {
  14. find: function find(callbackfn /* , that = undefined */) {
  15. return $find(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  16. }
  17. });
  18. // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
  19. addToUnscopables(FIND);