es.array.of.js 889 B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var global = require('../internals/global');
  4. var fails = require('../internals/fails');
  5. var isConstructor = require('../internals/is-constructor');
  6. var createProperty = require('../internals/create-property');
  7. var Array = global.Array;
  8. var ISNT_GENERIC = fails(function () {
  9. function F() { /* empty */ }
  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. });