_initCloneArray.js 692 B

1234567891011121314151617181920212223242526
  1. /** Used for built-in method references. */
  2. var objectProto = Object.prototype;
  3. /** Used to check objects for own properties. */
  4. var hasOwnProperty = objectProto.hasOwnProperty;
  5. /**
  6. * Initializes an array clone.
  7. *
  8. * @private
  9. * @param {Array} array The array to clone.
  10. * @returns {Array} Returns the initialized clone.
  11. */
  12. function initCloneArray(array) {
  13. var length = array.length,
  14. result = new array.constructor(length);
  15. // Add properties assigned by `RegExp#exec`.
  16. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  17. result.index = array.index;
  18. result.input = array.input;
  19. }
  20. return result;
  21. }
  22. module.exports = initCloneArray;