esnext.map.find.js 838 B

12345678910111213141516171819
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var anObject = require('../internals/an-object');
  4. var bind = require('../internals/function-bind-context');
  5. var getMapIterator = require('../internals/get-map-iterator');
  6. var iterate = require('../internals/iterate');
  7. // `Map.prototype.find` method
  8. // https://github.com/tc39/proposal-collection-methods
  9. $({ target: 'Map', proto: true, real: true, forced: true }, {
  10. find: function find(callbackfn /* , thisArg */) {
  11. var map = anObject(this);
  12. var iterator = getMapIterator(map);
  13. var boundFunction = bind(callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  14. return iterate(iterator, function (key, value, stop) {
  15. if (boundFunction(value, key, map)) return stop(value);
  16. }, { AS_ENTRIES: true, IS_ITERATOR: true, INTERRUPTED: true }).result;
  17. }
  18. });