Constructor
new Collection(baseObject, limitopt)
Construct a Collection
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
baseObject |
Class
|
The base class for all items |
|
limit |
Number
|
<nullable> |
Max number of items to hold |
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
baseObject |
Class
|
The base class for all items |
|
limit |
Number
|
<optional> |
Max number of items to hold |
Extends
- Map
Methods
add(obj, extraopt, replaceopt) → {Class}
Add an object
- Source:
Parameters:
| Name | Type | Attributes | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
obj |
Object
|
The object data
|
|||||||
extra |
Class
|
<optional> |
An extra parameter the constructor may need |
||||||
replace |
Boolean
|
<optional> |
Whether to replace an existing object with the same ID |
Returns:
- Type:
-
Class
The existing or newly created object
every(func) → {Boolean}
Returns true if all elements satisfy the condition
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
func |
function
|
A function that takes an object and returns true or false |
Returns:
- Type:
-
Boolean
Whether or not all elements satisfied the condition
filter(func) → {Array.<Class>}
Return all the objects that make the function evaluate true
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
func |
function
|
A function that takes an object and returns true if it matches |
Returns:
- Type:
-
Array.<Class>
An array containing all the objects that matched
find(func) → (nullable) {Class}
Return the first object to make the function evaluate true
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
func |
function
|
A function that takes an object and returns true if it matches |
Returns:
- Type:
-
Class
The first matching object, or undefined if no match
map(func) → {Array}
Return an array with the results of applying the given function to each element
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
func |
function
|
A function that takes an object and returns something |
Returns:
- Type:
-
Array
An array containing the results
random() → (nullable) {Class}
Get a random object from the Collection
- Source:
Returns:
- Type:
-
Class
The random object, or undefined if there is no match
reduce(func, initialValueopt) → {any}
Returns a value resulting from applying a function to every element of the collection
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
func |
function
|
A function that takes the previous value and the next item and returns a new value |
|
initialValue |
any
|
<optional> |
The initial value passed to the function |
Returns:
- Type:
-
any
The final result
remove(obj) → (nullable) {Class}
Remove an object
- Source:
Parameters:
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
obj |
Object
|
The object
|
Returns:
- Type:
-
Class
The removed object, or null if nothing was removed
some(func) → {Boolean}
Returns true if at least one element satisfies the condition
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
func |
function
|
A function that takes an object and returns true or false |
Returns:
- Type:
-
Boolean
Whether or not at least one element satisfied the condition
update(obj, extraopt, replaceopt) → {Class}
Update an object
- Source:
Parameters:
| Name | Type | Attributes | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
obj |
Object
|
The updated object data
|
|||||||
extra |
Class
|
<optional> |
An extra parameter the constructor may need |
||||||
replace |
Boolean
|
<optional> |
Whether to replace an existing object with the same ID |
Returns:
- Type:
-
Class
The updated object