The Power of Prototype.js

by Kurt Cagle

Computer languages evolve across an interesting number of vectors, and not always in ways that the original designers had planned. For every high level, top-down decision to implement new features and capabilities, there are interesting bits of best practices, useful libraries, and design patterns that can, subtly and sometimes not so subtly, change the course of direction of a language in critical ways.

AJAX is a good case in point - I'm in the process of writing on AJAX for a book, and occasionally I have to step out of my own preconceived notions of where the language (principally refering to JavaScript here and not the XML side) has been and look at where the language is going in terms of its own long and winding path. Certainly Ruby has been influencing things by bundling in interesting JavaScript components on the server side, but I think a more interesting case in point is the use of a set of libraries - collected together as prototype.js - that are rapidly reshaping how we use the language, especially in the context of web browsers.

11 Comments

Andrea Campi
2006-06-10 22:07:43
The problem with the $() function is that it encourages you to write code like the XUL example: multiple calls to $(), and thus to the relatively expensive document.getElementById, were moved inside the loop.


This doesn't need to happen, but it looks nice, so many people would go for it. Vice versa, if you moved the calls to $() you would end up with code very similar to the initial one, thus making $() much less actractive.

Ryan Bates
2006-06-13 10:47:44
Hmm, perhaps some kind of caching could be added to the $ function so you can still put it in a loop and not have so many calls to getElementById? Just a thought.
John
2006-09-21 15:18:23
This article suffers from the same problem I find in so many tech books - long, complicated examples to demonstrate a simple feature. Why would you use a portion of an XUL app to demonstrate getElementById? This article could have been a lot more informative with simpler, more straightforward examples.
Alex
2006-10-05 01:26:46
I have started to put together a wiki about Prototype. Sergio Pereira's documentation is wonderful, but this way everyone can contribute to the documentation. It would be much like the annotated PHP help downloadable from php.net.


Have a look at http://www.formar.se/prototype


2006-12-07 02:25:53
frf
manish
2007-01-30 22:50:31
no good work pls work again on this topick

2007-06-28 05:25:06
this does not wrk
Raul Hiero
2007-07-14 05:53:13
Is there transformation of these scripts in php? I would like to implement it on my blog.
prasad
2007-09-29 00:41:21
When i tried to make use of the prototype functions as $,$F..etc i get an error as such "$" is not defined can you sort out the problem where i go wrong..I had used this just to retrieve a value from a form.


Thanx in advance

China Landscape
2008-04-09 20:09:34
Seams not working for me...
Amit Shah
2008-06-23 23:14:00
Some thing is missing in this example. It is not working at my end.