美文网首页
18.类数组

18.类数组

作者: Sune小叶子 | 来源:发表于2018-02-26 22:43 被阅读0次

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

    var obj = {

        "0" : 0,

        "1" : 1,

        "length":2,

        "push":Array.prototype.push,    

        "splice":Array.prototype.splice

    }

    obj.push("c");

    obj.push("d")

    Array.prototype.push = function(target){

            obj[obj.length] = target;

            obj.length ++;

    }

    相关文章

      网友评论

          本文标题:18.类数组

          本文链接:https://www.haomeiwen.com/subject/ohpuxftx.html