esnext.map.merge.js 751 B

123456789101112131415161718192021
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var aCallable = require('../internals/a-callable');
  4. var anObject = require('../internals/an-object');
  5. var iterate = require('../internals/iterate');
  6. // `Map.prototype.merge` method
  7. // https://github.com/tc39/proposal-collection-methods
  8. $({ target: 'Map', proto: true, real: true, arity: 1, forced: true }, {
  9. // eslint-disable-next-line no-unused-vars -- required for `.length`
  10. merge: function merge(iterable /* ...iterables */) {
  11. var map = anObject(this);
  12. var setter = aCallable(map.set);
  13. var argumentsLength = arguments.length;
  14. var i = 0;
  15. while (i < argumentsLength) {
  16. iterate(arguments[i++], setter, { that: map, AS_ENTRIES: true });
  17. }
  18. return map;
  19. }
  20. });