Tuesday, October 16th, 2007

Prototype 1.6.0 RC1: Changes to the Class and Event APIs, Hash rewrite, and bug fixes

Category: JavaScript, Library, Prototype

Sam Stephenson has announced Prototype 1.6.0 RC1 which has “fixed a handful of bugs and made some changes to the Class and Event APIs in response to your feedback. We’ve also addressed a long-standing issue with the Hash class.”

For example, they show how they changed from:


  1. var Foo = Class.create();
  2. Class.extend(Foo, { /* instance methods */ });



  1. var Foo = Class.create();
  2. Foo.addMethods({ /* instance methods */ });

Other changes are:

  • Completely rewriten of the Hash class
  • Changes to the Event API
  • Element#wrap now returns the newly created wrapper element instead of the element being wrapped.
  • document.getElementsByClassName and Element#getElementsByClassName are now deprecated, since native implementations of these methods return a live NodeList, while we can only return a static Array. Please use $$ or Element#select instead.

Posted by Dion Almaer at 5:56 pm

4.1 rating from 34 votes


Comments feed TrackBack URI

Maybe I am wrong, but “document.getElementsByClassName” does not yet exist in all the browsers. So how can they remove such a useful function just because FF 3.0 is going to support it in a better way?

Comment by Philip Plante — October 16, 2007

…also new from Prototype:

Comment by Mark Holton — October 16, 2007

Philip: use $$(‘.className’) instead or element.select(‘.className’);

Comment by Tobie Langel — October 16, 2007

OMG!!! When I tested Prototype 1.6 a few months ago, I found it somewhat clunky in the new Class support, but they seem to have addressed my concerns superbly and I didn’t need to tell them how to do it! Great job! Hopefully this will mean that I’ll be able to adopt it in a huge scale, like in potentially hundreds of classes.

Comment by Joao — October 16, 2007

Hi Philip-

That’s a good question. You’re right, getElementsByClassName does not yet exist in all browsers (it’s only available in the Firefox 3 alphas now). But Firefox’s implementation is incompatible with ours (it returns a NodeList instead of an Array, so you’d need to convert its return value to an array first before using it like you’d be accustomed to using Prototype’s), and they’ve unfortunately chosen to implement it in such a way that prevents us from overriding it with our own version (see Bugzilla #390411 for details).

Part of Prototype’s design philosophy is that our API should behave consistently on all supported browsers. So in order to pave the way for Firefox 3 compatibility, we’ll have to deprecate our implementation of getElementsByClassName. FWIW, Dean Edwards has chosen to do the same in his Base2 library.

Comment by Sam Stephenson — October 16, 2007

In addition to FF 3, Opera 9.5 supports getElementsByClassName natively.

Comment by Les — October 16, 2007

ouch… Good update in general, but I think many people will dislike the new Hash changes if they used it extensively.

The domready event on the document namespace needs a looking at, it’s still broken, but at least the embaracing error is gone =P

Comment by Ben — October 17, 2007

Sam is my Hero, pave away my man! ..)
Personally I Digg the revised hash class, much cleaner / tighter IMHO.

Comment by advanced — October 17, 2007

@mislav: whoops, no bug with the domready event, I made a pretty noob mistake in not noticing the reformat of the eventtype (“dom:loaded”), nice way of standardizing eventtypes without losing the context btw ;).
Hash class is also nice and cleaner this way, but imagine the overhaul needed for existing applications that built heavily on the hash class =P hash[key].assets[i] ===> hash.get(“key”).assets[i]
Also, simulating the getter/setter functionality like this, slows down performance/speed a bit and might be noticable on large scale applications. (which made me stop using objects with getter/setters in some projects, directly changing values is faster).

Comment by ben — October 19, 2007

Leave a comment

You must be logged in to post a comment.