SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 131 | Next

Jonathan Snook, Aaron Gustafson, Stuart Langridge, and Dan Webb

"Accelerated DOM Scripting with Ajax, APIs, and Libraries"

Far above any other issue, event handling is
the biggest problem that web developers using JavaScript have to deal with. Libraries solve
this problem by creating a unified interface for attaching events, maintaining object scope,
and stopping events. Let??™s take a look at an example from Prototype:
Event.observe(element, 'click',
(function(){ alert(this.href) }).bindAsEventListener(element)
);
In Prototype an Event object has an observe() method that enables you to observe
events on a particular object. You want to track a click event on an element (a link, in this
case). The third parameter enables you to pass in a function to be called when the event is
fired. Because this is a simple example, I created an anonymous function, but notice the
method bindAsEventListener(). This method takes a single parameter: the element that
should have scope from within the function. When the function gets called, this will refer
to element. The bindAsEventListener() method makes use of the apply() method (refer to
Chapter 3), which ensures that scope is maintained.
Ajax
Ajax originally stood for Asynchronous JavaScript and XML, but it has morphed into an
umbrella term that encapsulates a number of technologies. At the core of Ajax, though, is still
the idea of using JavaScript to communicate with the server to send and receive data without
having to refresh the page. This is done using the XMLHttpRequest object, often referred to as
the XHR object.


Pages:
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6