Chapter 10. Prototype Reference

The Prototype JavaScript framework by Sam Stephenson is designed to ease development of dynamic web applications. It extends core JavaScript classes and adds new ones to provide powerful features, especially for working with Ajax and manipulating DOM elements. In many ways, it also bridges part of the gap between the JavaScript and Ruby languages—particularly by borrowing ideas from Ruby’s Enumerable module.

Tip

This chapter is by Sergio Pereira and Scott Raymond. It covers version 1.5.0_rc2.

Prototype can be downloaded from its web site, http://prototypejs.org.

This chapter organizes Prototype’s functionality into four major sections: Ajax support (wrappers for the XMLHttpRequest object enabling easy two-way communication with remote servers), DOM manipulation (a slew of methods for interacting with page elements), form manipulation (DOM manipulation methods specific to forms and form elements), and core extensions (convenient tools for working with JavaScript data structures, through new classes and extensions of core classes).

All of the code examples in this chapter are JavaScript. But because so much of Prototype is designed to work with HTML and DOM objects, many examples also include some HTML markup at the beginning, formatted as a JavaScript comment:

// <p>Example Paragraph</p>

JavaScript comments are also used to denote the return value of methods. For example:

// => 'result'

Another example:

// <p id="one">One</p> $('one').innerHTML; // => 'One' ...

Get Ajax on Rails now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.