构造
new Collection(构造集合时的数据, {unique})
参数
| 名称 | 类型 | 缺省值 | 说明 |
|---|---|---|---|
构造集合时的数据 |
|||
{unique} |
Object |
成员
| 名称 | 说明 |
|---|---|
| array_ | 集合数据 |
| unique_ | 集合中的对象是否不能重复 |
方法列表
| 名称 | 说明 |
|---|---|
| assertUnique_() | 唯一性检查 |
| clear() | 清空集合 |
| extend() | 将数组添加到集合中 |
| forEach() | 遍历方法 |
| getArray() | 返回数组对象 |
| getLength() | Get the length of this collection. |
| insertAt(index, elem) | Insert an element at the provided index. |
| item() | 返回指定index的数据 |
| pop() | Remove the last element of the collection and return it.
Return |
| push(elem) | Insert the provided element at the end of the collection. |
| remove(elem) | Remove the first occurrence of an element from the collection. |
| removeAt(index) | Remove the element at the provided index and return it.
Return |
| setAt(index, elem) | Set the element at the provided index. |
详细说明
assertUnique_()
唯一性检查
clear()
清空集合
extend()
将数组添加到集合中
forEach()
遍历方法
getArray()
返回数组对象
getLength()
Get the length of this collection.
返回值
The length of the array.
- Type
- number
insertAt(index, elem)
Insert an element at the provided index.
参数
| 名称 | 类型 | 缺省值 | 说明 |
|---|---|---|---|
index |
number | Index. |
|
elem |
T | Element. |
item()
返回指定index的数据
pop()
Remove the last element of the collection and return it.
Return undefined if the collection is empty.
返回值
Element.
- Type
- T | undefined
push(elem)
Insert the provided element at the end of the collection.
参数
| 名称 | 类型 | 缺省值 | 说明 |
|---|---|---|---|
elem |
T | Element. |
返回值
New length of the collection.
- Type
- number
remove(elem)
Remove the first occurrence of an element from the collection.
参数
| 名称 | 类型 | 缺省值 | 说明 |
|---|---|---|---|
elem |
T | Element. |
返回值
The removed element or undefined if none found.
- Type
- T | undefined
removeAt(index)
Remove the element at the provided index and return it.
Return undefined if the collection does not contain this index.
参数
| 名称 | 类型 | 缺省值 | 说明 |
|---|---|---|---|
index |
number | Index. |
返回值
Value.
- Type
- T | undefined
setAt(index, elem)
Set the element at the provided index.
参数
| 名称 | 类型 | 缺省值 | 说明 |
|---|---|---|---|
index |
number | Index. |
|
elem |
T | Element. |
搜索