esnext.map.map-keys.js 801 B

1234567891011121314151617181920212223
  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 MapHelpers = require('../internals/map-helpers');
  6. var iterate = require('../internals/map-iterate');
  7. var Map = MapHelpers.Map;
  8. var set = MapHelpers.set;
  9. // `Map.prototype.mapKeys` method
  10. // https://github.com/tc39/proposal-collection-methods
  11. $({ target: 'Map', proto: true, real: true, forced: true }, {
  12. mapKeys: function mapKeys(callbackfn /* , thisArg */) {
  13. var map = aMap(this);
  14. var boundFunction = bind(callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  15. var newMap = new Map();
  16. iterate(map, function (value, key) {
  17. set(newMap, boundFunction(value, key, map), value);
  18. });
  19. return newMap;
  20. }
  21. });