es.array.flat-map.js 803 B

123456789101112131415161718192021
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var flattenIntoArray = require('../internals/flatten-into-array');
  4. var toObject = require('../internals/to-object');
  5. var toLength = require('../internals/to-length');
  6. var aFunction = require('../internals/a-function');
  7. var arraySpeciesCreate = require('../internals/array-species-create');
  8. // `Array.prototype.flatMap` method
  9. // https://github.com/tc39/proposal-flatMap
  10. $({ target: 'Array', proto: true }, {
  11. flatMap: function flatMap(callbackfn /* , thisArg */) {
  12. var O = toObject(this);
  13. var sourceLen = toLength(O.length);
  14. var A;
  15. aFunction(callbackfn);
  16. A = arraySpeciesCreate(O, 0);
  17. A.length = flattenIntoArray(A, O, O, sourceLen, 0, 1, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  18. return A;
  19. }
  20. });