esnext.map.map-values.js 1.1 KB

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var getBuiltIn = require('../internals/get-built-in');
  4. var bind = require('../internals/function-bind-context');
  5. var call = require('../internals/function-call');
  6. var aCallable = require('../internals/a-callable');
  7. var anObject = require('../internals/an-object');
  8. var speciesConstructor = require('../internals/species-constructor');
  9. var getMapIterator = require('../internals/get-map-iterator');
  10. var iterate = require('../internals/iterate');
  11. // `Map.prototype.mapValues` method
  12. // https://github.com/tc39/proposal-collection-methods
  13. $({ target: 'Map', proto: true, real: true, forced: true }, {
  14. mapValues: function mapValues(callbackfn /* , thisArg */) {
  15. var map = anObject(this);
  16. var iterator = getMapIterator(map);
  17. var boundFunction = bind(callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  18. var newMap = new (speciesConstructor(map, getBuiltIn('Map')))();
  19. var setter = aCallable(newMap.set);
  20. iterate(iterator, function (key, value) {
  21. call(setter, newMap, key, boundFunction(value, key, map));
  22. }, { AS_ENTRIES: true, IS_ITERATOR: true });
  23. return newMap;
  24. }
  25. });