码迷,mamicode.com
首页 > 编程语言 > 详细

类数组

时间:2019-02-09 00:57:50      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:cti   console   array   func   原理   his   nbsp   fun   splice   

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;

 

类数组

标签:cti   console   array   func   原理   his   nbsp   fun   splice   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!