esnext.map.find-key.js 704 B

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