esnext.set.map.js 779 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var bind = require('../internals/function-bind-context');
  4. var aSet = require('../internals/a-set');
  5. var SetHelpers = require('../internals/set-helpers');
  6. var iterate = require('../internals/set-iterate');
  7. var Set = SetHelpers.Set;
  8. var add = SetHelpers.add;
  9. // `Set.prototype.map` method
  10. // https://github.com/tc39/proposal-collection-methods
  11. $({ target: 'Set', proto: true, real: true, forced: true }, {
  12. map: function map(callbackfn /* , thisArg */) {
  13. var set = aSet(this);
  14. var boundFunction = bind(callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  15. var newSet = new Set();
  16. iterate(set, function (value) {
  17. add(newSet, boundFunction(value, value, set));
  18. });
  19. return newSet;
  20. }
  21. });