es.array.of.js 832 B

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