In the following snippets the subclassed array behaves differently from original arrays. Why?
function Arr() {}
Arr.prototype = new Array();
var iArr = new Arr();
iArr[0] = 9;
iArr[5] = 10;
console.log(iArr.length);
console.log(iArr[0]);
console.log(iArr[5]);
iArr.push(87);
console.log(iArr.length);
console.log(iArr[0]);
console.log(iArr[5]);
results in
0
9
10
1
87
10
while
var iArr = new Array();
iArr[0] = 9;
iArr[5] = 10;
console.log(iArr.length);
console.log(iArr[0]);
console.log(iArr[5]);
iArr.push(87);
console.log(iArr.length);
console.log(iArr[0]);
console.log(iArr[5]);
gives
6
9
10
7
9
10
what I would have expected for the first snippet as well.
I cannot understand why the length property in the first snippet does not change through accessing elements by index.