Enumeration and Object Oriented JavaScript

 

*AnimTree
*Tabs
*GlideMenus
*DragLib

Conclusion

Enumeration might seem simple on the outside. Scratching beneath the surface, it's obviously not as simple as it seems.

All of the major libraries attempt to deal with the complications of enumeration, and the related browser bugs. The result is heavy, inefficient code whose meaning is obscured by it's workarounds for language deficiencies and browser bugs.

Enumerability in JavaScript creates a serious problem.

The language should be amended to support a practical and relevant set of collections to provide a useful alternative to Object as a hash table.

If the language defines this well, and browsers support the language perfectly, library code can be much smaller. Programs use more appropriate collection types, and code can be more meaningful.

My ES4 Recommendations

Public APIs are forever. Good code is modular code. Keep flexible and expect change.

Data Structures, Collections

  1. typed Arrays
  2. Enum

    (typesafe, compact, reduces RuntimeErrors)

  3. Generics
  4. Map<T,T>
  5. SortedSet<T>
  6. ListIterator<T>

    (the already proposed iterators are just a slight improvement from for in)

  7. The Iterators and Generators proposals are all bad.

    They are bad because they continue down the path of object-as-a-hashtable. They do not seem to fulfill any use cases.

    There are a number of problems with each individual proposal, such as forcing the user to use exception handling for normal termination of the loop.

Each of the above Collection types (not ListIterator) could support most of the Array Generics.

Glossary

borrow
add properties of a supplier object as properties to receiver object This is usually done using a for in loop. It's kind of like doing a merge on a checkin.
enumerate
Using the for in statement to expose object properties (§12.6.4)
iterate
Using the for statement (§12.6.3)
override
shadow or replace a property value
prototype chain
linkage of the internal [[Prototype]] objects.
replace
give a new value to a object's own property
shadow
hide a property in the prototype chain by declaring it sooner in the object's prototype chain
white-box testing
Using an internal perspective of the system to test