//类数组 和数组类似 但是数组所有的方法类数组它都没有
/*test(1,2,3,4,5);
function test(){
console.log(arguiments);
arguiments.push(7);
}
*/
/*
属性要为索引(数字)属性,必须有length属性,最好加上push方法
当加上splice之后 长得越来越像数组 但是依旧是对象 也可以当数组一样用
*/
let obj = {
"2" : "b" ,
"3" : "c" ,
"length" : 2 ,
"push" : Array.prototype.push,
"splice" : Array.prototype.splice
}
obj.push("d");
//push是push在obj.length上更改元素,类似于上面的obj,
当没有第一位length的时候会自动显示obj[0]为empty
let arr = ["a" ,"b" ,"c"];
//好处
/*
Array.prototype.push = function(target){
this[this.length] = target ;
this.length ++ ;
}
当我们调用push方法的时候,里面的this指向变成被调用者,
上面的时对象obj调用,所以所有的this都变成了obj(所以obj.lenght会随着push方法的调用随之改变)
*/
类数组小记
最新推荐文章于 2022-07-10 21:30:08 发布