esnext.map.find-key.js 845 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.findKey` method
  8. // https://github.com/tc39/proposal-collection-methods
  9. $({ target: 'Map', proto: true, real: true, forced: true }, {
  10. findKey: function findKey(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(key);
  16. }, { AS_ENTRIES: true, IS_ITERATOR: true, INTERRUPTED: true }).result;
  17. }
  18. });