$.array-species-create.js 541 B

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