类数组

var obj = {
    '0' : 'a',
    '1' : 'b',
    '2' : 'c',
    'length' : 3,
    'push' : Array.prototype.push
}    

类数组:1、属性必须以索引(数字)为属性名

    2、需要要有length属性名

            3、最好加上push方法

类数组push的内部原理

Array.prototype.push = function(target){
    this[this.length] = target;
    this.length ++;    
}

阿里巴巴题目

var obj = {
    '2' : 'a',
    '3' : 'b',
    'length' : 2,
    'push' :Array.prototype.push
}

obj.push('c');
obj.push('d');
最后这个obj长什么样子?    

var obj = {
    '2' : 'c',

    '3' : 'd',

    length : 4
}

posted @ 2018-12-30 20:31  red东  阅读(315)  评论(0编辑  收藏  举报