如何使用js实现ArrayList

 function ArrayList(){
    this.arr=[],
    this.size=function(){
        return this.arr.length;
    },
    this.add=function(){
        if(arguments.length==1){
            this.arr.push(arguments[0]);
        }else if(arguments.length>=2){
            var deleteItem=this.arr[arguments[0]];
            this.arr.splice(arguments[0],1,arguments[1],deleteItem)
        }
        return this;
    },
    this.get=function(index){
        return this.arr[index];
    },
    this.removeIndex=function(index){
        this.arr.splice(index,1);
    },
    this.removeObj=function(obj){
        this.removeIndex(this.indexOf(obj));
    },
    this.indexOf=function(obj){
        for(var i=0;i

你可能感兴趣的:(如何使用js实现ArrayList)