jQuey List (unique)

jQuery.uniqueArray = function () {
    this.items = new Array();
    this.itemsCount = 0;
    this.add = function (value) {
        if (!this.contains(value)) {
            this.items.push(value);
            this.itemsCount++;
        }
        else
            throw "The value '" + value + "' allready exists."
    }

    this.contains = function (value) {
        return jQuery.inArray(value, this.items) > -1;
    }

    this.clear = function () {
        this.items = new Array();
        this.itemsCount = 0;
    }
    this.size = function () {
        return this.itemsCount;
    }

    this.isEmpty = function () {
        return this.size() == 0;
    }

    this.remove = function (value) {
        if (this.contains(value)) {
            var index = jQuery.inArray(value, this.items);
            this.items.splice(index, 1);
            this.itemsCount--;
        }
        else
            throw "value '" + value + "' does not exists."
    }
};

你可能感兴趣的:(unique)