species-constructor.js 606 B

123456789101112131415
  1. 'use strict';
  2. var anObject = require('../internals/an-object');
  3. var aConstructor = require('../internals/a-constructor');
  4. var isNullOrUndefined = require('../internals/is-null-or-undefined');
  5. var wellKnownSymbol = require('../internals/well-known-symbol');
  6. var SPECIES = wellKnownSymbol('species');
  7. // `SpeciesConstructor` abstract operation
  8. // https://tc39.es/ecma262/#sec-speciesconstructor
  9. module.exports = function (O, defaultConstructor) {
  10. var C = anObject(O).constructor;
  11. var S;
  12. return C === undefined || isNullOrUndefined(S = anObject(C)[SPECIES]) ? defaultConstructor : aConstructor(S);
  13. };