/**
 * js实现list
 * 
 */
function List() {
    this.value = [];

    /* 添加 */
    this.add = function(obj) {
        return this.value.push(obj);
    };

    /* 大小 */
    this.size = function() {
        return this.value.length;
    };

    /* 返回指定索引的值 */
    this.get = function(index) {
        return this.value[index];
    };

    /* 删除指定索引的值 */
    this.remove = function(index) {
        this.value.splice(index,1);
        return this.value;
    };

    /* 删除全部值 */
    this.removeAll = function() {
        return this.value = [];
    };

    /* 是否包含某个对象 */
    this.constains = function(obj) {
        for ( var i in this.value) {
            if (obj == this.value[i]) {
                return true;
            } else {
                continue;
            }
        }
        return false;
    };
    
    /* 是否包含某个对象 */
    this.getAll = function() {
        var allInfos = '';
        for ( var i in this.value) {
            if(i != (value.length-1)){
                allInfos += this.value[i]+",";
            }else{
                allInfos += this.value[i];
            }
        }
        alert(allInfos);
        return allInfos += this.value[i]+",";;
    };
    
}

 

相关文章:

  • 2021-09-20
  • 2021-06-20
  • 2022-12-23
  • 2021-05-07
  • 2021-07-26
  • 2022-12-23
  • 2021-11-15
猜你喜欢
  • 2022-12-23
  • 2021-08-10
  • 2021-08-16
  • 2021-09-25
  • 2021-05-31
  • 2021-06-02
  • 2022-12-23
相关资源
相似解决方案