t really break the web. First of all, the only issue is that after modifying the "Array.prototype", using "for … in" loops on an Array returns each attached Function, as well as each member of the Array, so you would have to do what YUI does and ignore theses keys. However, you would only need to use "for … in" loops if you were creating associative arrays, and an associative Array can be represented instead with an Object, so there is no need to use them. Therefore, it is good practice to use Object in place of any associative Arrays. If you follow this practice, then one only needs to iterate numerically on an Array, never needing the "for … in" loop; allowing us to safely extend "Array.prototype" with useful methods.
The most important method is probably the "Array.get" Function attached statically to Array. This method converts Array-like objects such as arguments
to an Array, so that you get all the syntactic sugar of "array.js" on non-arrays. This is most useful in conjunction with "document.getElementsByTagName" or simply arguments
I have also added the concept of a pointer to Array so that you can iterate through the Array with functions like: next
, and current
, which point to the appropriate index in the Array. Some other useful short-hand methods like: first
have also been added.