Enumerator object
Provides a faster iterating mechanism for collections.
The Enumerator object is useful if you want iterate through a large collection.
Iterating through a large collection with the Enumerator object is faster than any other way in JavaScript. Example 2 shows a speed test.
The Enumerator object allows using a walk-through mechanism to iterate through the items.
There is a pointer, which designates the currently selected element and can be used to navigate within the Enumerator object. In a newly created Enumerator object, the currently selected item is the first item of the collection.
Iterating through a large collection with the Enumerator object is faster than any other way in JavaScript. Example 2 shows a speed test.
The Enumerator object allows using a walk-through mechanism to iterate through the items.
There is a pointer, which designates the currently selected element and can be used to navigate within the Enumerator object. In a newly created Enumerator object, the currently selected item is the first item of the collection.
Syntax:
Creating a new Enumerator object:
var myEnum = new Enumerator ([collection]);
collection | Optional. Specifies the collection for enumeration. |
Members:
The Enumerator object inherits from the Enumerator.prototype and Function.prototype objects.
The following lists only contain the members of the Enumerator and Enumerator.prototype objects.
(*) - The method is inherited from the Enumerator.prototype.
Properties:
Property | Support | Description | |||||
---|---|---|---|---|---|---|---|
prototype | Returns a reference to the Enumerator.prototype object. The Enumerator.prototype object allows adding properties and methods to the Enumerator object that can be used with instances of the Enumerator object, like any predefined property or method. The prototype property is static, it cannot be accessed from an instance of the Enumerator object, only Enumerator.prototype is allowed. |
Methods:
Method | Support | Description | |||||
---|---|---|---|---|---|---|---|
atEnd ( )* | Returns a Boolean value that indicates whether the pointer of the Enumerator is at the end of the collection, or not. | ||||||
item ( )* | Returns the currently selected item (where the pointer is placed) from the collection. | ||||||
moveFirst ( )* | Moves the pointer of the Enumerator to the first item of the collection. | ||||||
moveNext ( )* | Moves the pointer of the Enumerator to the next item in the collection. |
(*) - The method is inherited from the Enumerator.prototype.
Examples:
Example 1:
This example shows how to iterate through the attributes collection with the Enumerator object:
Example 2:
This example shows a speed test for iterating through a collection with an Enumerator object:
|
External links:
User Contributed Comments