copyArray.js 487 Bytes
Newer Older
徐立's avatar
徐立 committed
1 2 3 4 5 6 7 8 9
/**
 * Copies the values of `source` to `array`.
 * 将“source”的值复制到“array”
 * @private
 * @param {Array} source 要从中复制值的数组.
 * @param {Array} [array=[]] 要将值复制到的数组.
 * @returns {Array} 返回数组.
 */
function copyArray(source, array) {
10 11
	let index = -1;
	const length = source.length;
徐立's avatar
徐立 committed
12

13 14 15 16 17
	array || (array = new Array(length));
	while (++index < length) {
		array[index] = source[index];
	}
	return array;
徐立's avatar
徐立 committed
18 19
}

20
export default copyArray;