JS Analog C # List of simple examples _javascript skills

Source: Internet
Author: User

Copy Code code as follows:

/*
* List size variable array
* version:1.0
*/
function List () {
This.list = new Array ();
};

/**
* Adds the specified element to the tail of this list.
* @param element specified by object
*/
List.prototype.add = function (object) {
This.list[this.list.length] = object;
};

/**
* Add list to the tail of this list.
* @param listObject a list
*/
List.prototype.addAll = function (listObject) {
This.list = This.list.concat (listobject.list);
};

/**
* Returns the element at the specified position in this list.
* @param index specified location
* @return element of this position
*/
List.prototype.get = function (index) {
return This.list[index];
};

/**
* Removes the element at the specified location in this list.
* @param index specified location
* @return element of this position
*/
List.prototype.removeIndex = function (index) {
var object = This.list[index];
This.list.splice (index, 1);
return object;
};

/**
* Removes the specified element from this list.
* @param object to specify elements
* @return element of this position
*/
List.prototype.remove = function (object) {
var i = 0;
for (; i < this.list.length; i++) {
if (this.list[i] = = object) {
Break
}
}
if (i >= this.list.length) {
return null;
} else {
return This.removeindex (i);
}
};

/**
* Remove all elements from this list.
*/
List.prototype.clear = function () {
This.list.splice (0, this.list.length);
};

/**
* Returns the number of elements in this list.
* Number of @return elements
*/
List.prototype.size = function () {
return this.list.length;
};

/**
* Returns a list of the specified start (including) and end (not included) in the list.
* @param start position
* @param End Position
* @return a new list
*/
List.prototype.subList = function (start, end) {
var list = new List ();
List.list = This.list.slice (start, end);
return list;
};

/**
* Returns True if the list contains no elements.
* @return True or False
*/
List.prototype.isEmpty = function () {
return this.list.length = = 0;
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.