PhpRiot
Download Article
Download this article or the entire “Eight Weeks of Prototype” series with all listings and files.




More information
Related Books
JavaScript: The Good Parts

JavaScript: The Good Parts

Most programming languages contain good and bad parts, but JavaScript has more than its share...

jQuery: Novice to Ninja

jQuery: Novice to Ninja

jQuery: Novice to Ninja is a compilation of best-practice jQuery solutions to meet the most...
PhpRiot Newsletter
Your Email Address:

More information

Eight Weeks of Prototype: Week 3, Prototype Data Types

Enumerable Data Types

An enumerable data type is one that contains a series of values over which you can loop. There are already two such types in JavaScript (that is, arrays and objects), however Prototype provides a united interface for accessing for accessing each of these types in the same manner. Additionally, Prototype makes it possible for you to create your own enumerated types, all of which extend from the Enumerable object.

For example, regardless of the type of data the your enumerated type holds, you can call the size() method to determine the number of elements in the enumerable object.

Note: There is a slight ambiguity between JavaScript objects and the Prototype Hash object. Hash is an extension of the normal JavaScript object, but as we will see later in this article, values are read and written differently since Prototype 1.6.0. When you create a new JavaScript object, it is not automatically a hash (unless arrays, which are automatically extended).

In This Article