AJAX - The Complete Reference

(avery) #1

PART II


Chapter 5: Developing an Ajax Library 221


Function Description Example
$$ Takes a CSS string as an
argument and returns an array
of matches.

var nodes = $$('a.nav');

$A Takes an object and converts
it into an array. If passed a
string, each character gets its
own index. If passed a DOM
NodeLists, it changes it to an
array.

var someNodeList = $('colors').
getElementsByTagName('option');
var nodes = $A(someNodeList);

$F Returns the value of a given
form element.

var name = $F('firstname');

$H Creates a hash. var h = $H({ name: 'Prototype',
version: 1.5 });
$w Splits a string into an array
using space as a delimiter.

var colorArray = $W('Red Orange
Yellow Green');
getElementsByClassName Returns the elements that
match the given class name.
Starts at document if no start
node is specified.

var links =
document.getElementsByClassName
('nav', $('headerDiv'));

Try.these A simplified tr y/catch. In
this case, you pass multiple
functions and the code will tr y
to execute each one until one
succeeds. That one will be
returned.

Try.these(
function(){return new
XMLHttpRequest(); },
function(){return new
ActiveXObject(
"Msxml2.XMLHTTP.6.0" ); },

function(){ return new
ActiveXObject(
"Msxml2.XMLHTTP.3.0"); },

function(){return new
ActiveXObject
(" Msxml2.XMLHTTP"); },

function(){ return new
ActiveXObject(
"Microsoft.XMLHTTP"); }
);

TABLE 5-9 Sample of Useful Prototype Facilities (continued)
Free download pdf