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