shim.js 614 B

12345678910111213141516171819
  1. "use strict";
  2. var isFunction = require("../../function/is-function")
  3. , slice = Array.prototype.slice
  4. , defineProperty = Object.defineProperty
  5. , desc = { configurable: true, enumerable: true, writable: true, value: null };
  6. module.exports = function (/* …items*/) {
  7. var result, i, length;
  8. if (!this || this === Array || !isFunction(this)) return slice.call(arguments);
  9. result = new this((length = arguments.length));
  10. for (i = 0; i < length; ++i) {
  11. desc.value = arguments[i];
  12. defineProperty(result, i, desc);
  13. }
  14. desc.value = null;
  15. result.length = length;
  16. return result;
  17. };