Once you've been programming in a given language for awhile,
you tend to collect a number of utility functions to perform common tasks that
where different browser compatibilities and implementations often necessitate
but what it lacks in speed, it makes up for in versatility. As a case in point, here's
splitOnSpaces() function that uses a generic
curry() utility function to extend
It's a good idea to move the
function to a separate file, along with other general utility functions. Meanwhile,
thousands of other coders are doing the same thing. One
day, a fellow by the name of Sam Stephenson compiled a group of utilities
prototype.js", it's now called:
prototype-184.108.40.206.js" to reflect the latest version number. A core
team of developers work on the Prototype Framework, and other developers
are encouraged to contribute as well, in true open source fashion. In this article we'll
go over some of the key features of this exciting new tool and demonstrate how
it can make your life easier!
Let's take a look at some of the Prototype Framework's more useful functions.
$() function is the cornerstone of the Prototype Framework.
It's main purpose is to provide a handy shortcut for
and it's capable of doing more than that! In addition to an ID string,
$() function also accepts any number and combination of ID's and DOM
node references. This allows us to do some very interesting things with it,
such as apply the same method to several elements:
You can call methods directly on the results of the
because all elements returned by the function are extended with Prototype DOM
extensions, meaning that the elements possess all of the methods contained in
$$() function is Prototype's CSS Selector emulator. It returns
all matching elements, following the same rules as a selector in a CSS stylesheet.
For example, if you want to get all paragraph (
<P>) tags with the
class "bright", you would use the following:
$F() function returns the value of the requested form element.
For a 'text'
<input>, the function will return the data contained in the
element. For a
<select> element, the function will return the currently
Accepts an array-like collection (or anything with numeric indices)
and returns its equivalent as an actual
Array object. This is useful when you
would like to use
Array methods on a collection or enumerated list, such as
the arguments of a function. For instance, we could display all the arguments
in a function by using the
join() method, but the
arguments property that
exists in all functions doesn't inherit from