Prototype 1.6
The Complete API Reference
Sam Stephenson and the Prototype Team
1
http://www.prototypejs.org/
2
http://www.globalmoxie.com/
3
http://creativecommons.org/licenses/by-sa/2.5/
Prototype 1.6: The Complete API Reference
Sam Stephenson and the Prototype Team
Published March 2008. 1st edition for version 1.6 (v1.6.0.2).
Copyright © 2006-2008 Sam Stephenson. Some rights reserved.
Prototype
1
is a JavaScript framework that aims to ease development of dynamic web applications. Prototype was created by Sam Stephenson who re-
leased the framework as an open-source project in February 2005. Other members of the core development team are: Thomas Fuchs, Justin Palmer,
Andrew Dupont, Dan Webb, Scott Raymond, Mislav Marohni#, Christophe Porteneuve, Tobie Langel and Seth Dillingham.
This PDF book version of the Prototype API reference was created by Josh Clark
2
, but all content comes from the Prototype site and is the intellec-
tual property of Sam Stephenson and the Prototype core team.
This PDF is distributed under the Creative Commons Attribution-ShareAlike 2.5
3
. This means that you can copy, redistribute or create your own de-
rivative works from this PDF, provided that you do so with the same Creative Commons license and include the foregoing notice.
While every precaution has been taken in the preparation of this book, the publisher assumes no responsibility for errors or omissions, or for dam-
ages resulting from the use of the information contained herein.
Table of Contents
1. New in Prototype 1.6 ............................................................................................................1
Event API Enhancements ................................................................................................1
Complete rewrite of the Hash class ....................................................................................2
Function API Enhancements ............................................................................................3
Class API Enhancements .................................................................................................5
Ajax API Enhancements ..................................................................................................6
DOM API Enhancements ................................................................................................6
Template API Enhancements ...........................................................................................9
Extended grep semantics .................................................................................................9
Improved support for JavaScript 1.6 and WHATWG 1.0 standards ..................................... 10
2. Utility Methods .................................................................................................................. 11
$ .................................................................................................................................. 11
$$ ................................................................................................................................ 13
$A ............................................................................................................................... 15
$F ................................................................................................................................ 16
$H ............................................................................................................................... 16
$R ................................................................................................................................ 16
$w ................................................................................................................................ 17
Try.these ...................................................................................................................... 18
document.getElementsByClassName (deprecated) ................................................................ 18
3. Ajax .................................................................................................................................. 21
Ajax Options ................................................................................................................ 21
Ajax.PeriodicalUpdater ................................................................................................... 25
Ajax.Request ................................................................................................................. 28
Ajax.Responders ............................................................................................................ 32
Ajax.Response ............................................................................................................... 33
Ajax.Updater ................................................................................................................. 34
4. Array ................................................................................................................................ 37
Why you should stop using for…in to iterate (or never take it up) .................................... 37
What is a developer to do? .............................................................................................. 38
clear ............................................................................................................................. 39
clone ............................................................................................................................ 39
compact ....................................................................................................................... 39
each ............................................................................................................................. 40
first .............................................................................................................................. 40
flatten ........................................................................................................................... 40
from ............................................................................................................................ 40
indexOf ........................................................................................................................ 41
inspect .......................................................................................................................... 41
last ............................................................................................................................... 42
reduce .......................................................................................................................... 42