文章目录

类数组属性要为(数字索引),必须有length属性,最好加上push

1
2
3
4
5
6
7
8
9
//类数组
var obj = {
"0": 'a',
"1": 'b',
"2": 'c',
'length': '3',
'push': Array.prototype.push,
'splice': Array.prototype.splice
}

类数组的实现

1
2
3
4
5
//类数组的实现
Array.prototype.push = function (target) {
obj[obj.length] = target;
obj.length++;
}

1
2
3
4
5
6
7
8
var obj = {
'2':'a',
'3':'b',
'length':2,
'push':Array.prototype.push
}
obj.push('c');
obj.push('d');//2:c,3:d
文章目录