Class: Collection

.base. Collection

A class for collections of models

new Collection( [data] [, options])

Create a new Collection
Parameters:
Name Type Argument Default Description
data Array <optional>
[] An array of models to create the Collection from.
options Object <optional>
{} An options object
Properties
Name Type Argument Description
model Object <optional>
The constructor for the model to use in this collection. If provided, each item in the collection will become an instance of this model.

Extends

Methods


emit(event [, args])

Triggers the callbacks for a given event. Subsequent arguments will be passed to the event callbacks.
Parameters:
Name Type Argument Description
event String The event name to trigger
args Any <optional>
<repeatable>
Additional arguments to pass to the event callback
Inherited From:
Returns:
Returns a Promise that resolves when all callbacks are complete
Type
Object

off( [event] [, callback])

Unsubscribe from one or more events on this object
Parameters:
Name Type Argument Description
event String <optional>
The event to remove. If none is specified, all events will be removed.
callback function <optional>
The callback to remove. If none is specified, all callbacks for the specified event will be removed.
Inherited From:
Returns:
Returns the Emitter object
Type
Object

on(event, callback)

Subscribe to an event on this object, by binding a callback function to the name of the event. Callbacks may be Promises or regular functions.
Parameters:
Name Type Description
event String | Object The name of the event to subscribe to. May also be an object mapping event names to callback functions
callback function The callback function to invoke whenever the specified event is fired
Inherited From:
Returns:
Returns the emitter object
Type
Object

once(event, callback)

Subscribe to an event on this object for one time only. After the event is triggered, the callback will be removed. Callbacks may be Promises or regular functions.
Parameters:
Name Type Description
event String The name of the event to subscribe to
callback function The callback function to invoke when the event is fired
Inherited From:
Returns:
Returns the emitter object
Type
Object