esnext.set.union.js 700 B

123456789101112131415161718
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var getBuiltIn = require('../internals/get-built-in');
  4. var aCallable = require('../internals/a-callable');
  5. var anObject = require('../internals/an-object');
  6. var speciesConstructor = require('../internals/species-constructor');
  7. var iterate = require('../internals/iterate');
  8. // `Set.prototype.union` method
  9. // https://github.com/tc39/proposal-set-methods
  10. $({ target: 'Set', proto: true, real: true, forced: true }, {
  11. union: function union(iterable) {
  12. var set = anObject(this);
  13. var newSet = new (speciesConstructor(set, getBuiltIn('Set')))(set);
  14. iterate(iterable, aCallable(newSet.add), { that: newSet });
  15. return newSet;
  16. }
  17. });