Enumerable#nextObject()

nextObject (index, previousObject, context) Objectprivate

Defined in packages/ember-runtime/lib/mixins/enumerable.js:102

Required. You must implement this method to apply this mixin.

Implement this method to make your class enumerable.

This method will be called repeatedly during enumeration. The index value will always begin with 0 and increment monotonically. You don't have to rely on the index value to determine what object to return, but you should always check the value and start from the beginning when you see the requested index is 0.

The previousObject is the object that was returned from the last call to nextObject for the current iteration. This is a useful way to manage iteration if you are tracing a linked list, for example.

Finally the context parameter will always contain a hash you can use as a "scratchpad" to maintain any other state you need in order to iterate properly. The context object is reused and is not reset between iterations so make sure you setup the context with a fresh state whenever the index parameter is 0.

Generally iterators will continue to call nextObject until the index reaches the current length-1. If you run out of data before this time for some reason, you should simply return undefined.

The default implementation of this method simply looks up the index. This works great on any Array-like objects.

Parameters:

index Number
the current index of the iteration
previousObject Object
the value returned by the last call to `nextObject`.
context Object
a context object you can use to maintain state.

Returns:

Object
the next object in the iteration or undefined
doc_EmberJs
2016-11-30 16:52:00
Comments
Leave a Comment

Please login to continue.