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