Constructor
# new Collection(baseObject, limitopt)
Construct a Collection
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 |
- Since:
- v2.5.2-beta.1
- Source:
Extends
- Map
Methods
# add(obj, extraopt, replaceopt) → {Class}
Add an object
Name | Type | Attributes | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
obj | Object | The object data Properties
| |||||||
extra | Class | <optional> | An extra parameter the constructor may need | ||||||
replace | Boolean | <optional> | Whether to replace an existing object with the same ID |
- Source:
The existing or newly created object
- Type
- Class
# every(func) → {Boolean}
Returns true if all elements satisfy the condition
Name | Type | Description |
---|---|---|
func | function | A function that takes an object and returns true or false |
- Source:
Whether or not all elements satisfied the condition
- Type
- Boolean
# filter(func) → {Array.<Class>}
Return all the objects that make the function evaluate true
Name | Type | Description |
---|---|---|
func | function | A function that takes an object and returns true if it matches |
- Source:
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
Name | Type | Description |
---|---|---|
func | function | A function that takes an object and returns true if it matches |
- Source:
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
Name | Type | Description |
---|---|---|
func | function | A function that takes an object and returns something |
- Source:
An array containing the results
- Type
- Array
# random() → (nullable) {Class}
Get a random object from the Collection
- Source:
The random object, or undefined if there is no match
- Type
- Class
# reduce(func, initialValueopt) → {any}
Returns a value resulting from applying a function to every element of the collection
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 |
- Source:
The final result
- Type
- any
# remove(obj) → (nullable) {Class}
Remove an object
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
obj | Object | The object Properties
|
- Source:
The removed object, or null if nothing was removed
- Type
- Class
# some(func) → {Boolean}
Returns true if at least one element satisfies the condition
Name | Type | Description |
---|---|---|
func | function | A function that takes an object and returns true or false |
- Source:
Whether or not at least one element satisfied the condition
- Type
- Boolean
# update(obj, extraopt, replaceopt) → {Class}
Update an object
Name | Type | Attributes | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
obj | Object | The updated object data Properties
| |||||||
extra | Class | <optional> | An extra parameter the constructor may need | ||||||
replace | Boolean | <optional> | Whether to replace an existing object with the same ID |
- Source:
The updated object
- Type
- Class