es.array.of.js 893 B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var fails = require('../internals/fails');
  4. var isConstructor = require('../internals/is-constructor');
  5. var createProperty = require('../internals/create-property');
  6. var $Array = Array;
  7. var ISNT_GENERIC = fails(function () {
  8. function F() { /* empty */ }
  9. // eslint-disable-next-line es/no-array-of -- safe
  10. return !($Array.of.call(F) instanceof F);
  11. });
  12. // `Array.of` method
  13. // https://tc39.es/ecma262/#sec-array.of
  14. // WebKit Array.of isn't generic
  15. $({ target: 'Array', stat: true, forced: ISNT_GENERIC }, {
  16. of: function of(/* ...args */) {
  17. var index = 0;
  18. var argumentsLength = arguments.length;
  19. var result = new (isConstructor(this) ? this : $Array)(argumentsLength);
  20. while (argumentsLength > index) createProperty(result, index, arguments[index++]);
  21. result.length = argumentsLength;
  22. return result;
  23. }
  24. });