Prototype was
originally designed by Sam Stephenson (http://conio.net) and integrated into Ruby on
Rails (http://www.rubyonrails.org). Many of the ways that Prototype approaches problems
are similar in style to Ruby.
One of the reasons for Prototype??™s popularity is the way it makes many things much easier,
including the infamous dollar sign function ($). By using the dollar sign function, methods
are automatically attached to the returned DOM element, adding a lot more power to what
you can do with an element. Recent iterations of the library have improved on method chaining,
making it a formidable tool:
$('elementId').show(); // shows an element that was hidden using display:none
Prototype, unlike other libraries, really focuses heavily on addressing two key areas: working
with the DOM and application conveniences including lots of string functions, and a
custom enumeration object that is used to extend a custom hash object and the built-in Array
object. When it comes to building web applications??”especially Ajax-driven ones??”Prototype
is a solid solution.
CHAPTER 4 n LIBRARIES 87
The latest version of Prototype also features a double dollar function ($$) for using CSS
selectors to retrieve an array of elements. Here??™s a great example of how easy it can be used to
create an expand and collapse feature for an FAQ page:
What is an apple?
It's a fruit!
$$('.
Pages:
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149