首页 > 编程语言 > 详细

类数组

时间:2019-02-09 00:39:04      阅读:188      评论:0      收藏:0      [点我收藏+]
var obj = {
    ‘2‘ : 3,  
    ‘3‘ : 4,
    ‘length‘ : 2,
    ‘splice‘ : Array.prototype.splice,
    ‘push‘ : Array.prototype.push
};
obj.push(1);
obj.push(2);
console.log(obj)  // [empty × 2, 1, 2, splice: ?, push: ?]

// 原理
// Array.prototype.push = function(elem){
//     this[this.length] = elem;  // 当前元素最后位置添加类容
//     this.length ++;            // 让length 加一
// }

// obj[2] = 1;
// obj[3] = 2;

 

类数组

原文:https://www.cnblogs.com/xm16/p/10357019.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!