jQueryのソースコードを読んでいます。jQuery.merge の機能で
merge: function( first, second ) {
var i = first.length,
j = 0;
if ( typeof second.length === "number" ) {
for ( var l = second.length; j < l; j++ ) {
first[ i++ ] = second[ j ];
}
} else {
while ( second[j] !== undefined ) {
first[ i++ ] = second[ j++ ];
}
}
first.length = i;
return first;
}
理解できないことが2つあります。
- second.length のタイプをチェックしたのに、first.length のタイプをチェックしなかったのはなぜですか?
- Array の長さは自動的に増加するのに、なぜ手動で長さを設定する必要があるのでしょうか?
ありがとうございました。