merge 源码
- merge: function( first, second ) {
- var l = second.length, i = first.length, j = 0;
- // second可以是一个对象
- if (typeof l === "number" ) { // 如果second是数组
- for (; j < l; j++)
- first[i++] = second[j];
- }
- else { // 如果second不是数组
- // 如second = {}; second[0] = 1; second[1] = 2; second[2] = 3;
- while (second[j] !== undefined)
- first[i++] = second[j++];
- }
- first.length = i;
- return first;
- },
可以看出:
要想正常使用该函数,first的类型可以 为 数组 或 带有length的对象;second无要求,不过first对象只会添加second中 属性下标为数字对应 的值