//添加一个值 add(object) { list[list.length] = object; } //删除下标为index的值 removeIndex(index) { var object = this.list[index]; this.list.splice(index, 1); return object; } //删除元素object remove(object) { var i = 0; for (; i < list.length; i++) { if (list[i] === object) { break; } } if (i >= list.length) { return null; } else { return removeIndex(i); } } //获取list index下标的值 get(index) { return list[index]; } //移除list中的所有元素 removeAll() { list.splice(0, list.length); } //list大小 size () { return this.list.length; } //是否list为空 isEmpty() { return list.length == 0; }
时间: 2024-10-10 02:45:51