_array-species-constructor.js 475 B

12345678910111213141516
  1. var isObject = require('./_is-object');
  2. var isArray = require('./_is-array');
  3. var SPECIES = require('./_wks')('species');
  4. module.exports = function (original) {
  5. var C;
  6. if (isArray(original)) {
  7. C = original.constructor;
  8. // cross-realm fallback
  9. if (typeof C == 'function' && (C === Array || isArray(C.prototype))) C = undefined;
  10. if (isObject(C)) {
  11. C = C[SPECIES];
  12. if (C === null) C = undefined;
  13. }
  14. } return C === undefined ? Array : C;
  15. };