AJAX - The Complete Reference

(avery) #1

178 Part II: Applied Ajax^


it aim to do many things and none of them exceedingly well? Finally, is the library well
supported? In other words, is this library likely to be supported over the course of time, or are
you going to be stuck maintaining it yourself?
We also must address a somewhat contentious reason that JavaScript libraries are built: to
significantly change how JavaScript tends to be written. It is a bit disturbing to see libraries
make statements like, “making JavaScript suck less” as a design goal, especially when the less
“sucking” effect is often accomplished by trying to make JavaScript act more like some other
language. It is particularly troubling when these libraries override built-in aspects of the
language, thus making it quite difficult to intermix code from one library and another.
If you take the time to evaluate many libraries, it will also become very clear that some
authors want JavaScript to act more like other languages such as Ruby, Python, Java, or even
more like a Lisp-style language like ML. Interestingly, it is the raw dynamic power of
JavaScript that allows these well-intentioned folks to tersely implement their other language-
flavored approaches to JavaScript. If the JavaScript language really was so underpowered,
they simply wouldn’t be able to accomplish this feat so easily.
It is our strong opinion that programmers should attempt to work with JavaScript and
program it as JavaScript, not some other language. You may disagree with that opinion and
find the near meta-language approach of JavaScript mimicking aspects of a particular

Library Category Description
Ajax communications Minimally a librar y will wrap an XHR object, but good libraries
should address timeouts, retries, and error issues. Advanced
libraries may add support for histor y management, offline storage,
and persistence.
DOM utilities A librar y may provide methods to make working with DOM trees
easier. Extensions like getElementsByClassName() are
commonplace, but some libraries may have complex content
selection systems that rely on CSS or Xpath syntax.

Event management A significant headache for JavaScript developers is addressing
cross-browser event concerns. Because of poor event management
and long stays on the same page, Ajax applications that do not
manage events properly may leak memor y. Given this situation,
many libraries provide cross-browser and, hopefully, leak-proof
event handling functions.
Utility functions A decent Ajax librar y should provide functions to address the
serialization of form data. Other data format encoding and
decoding such as dealing with JSON is also commonly found.

UI widgets and effects Higher-level libraries may provide widgets that both encapsulate UI
and tie in with lower-level Ajax and DOM facilities. These libraries
also often provide basic animation and visual effects that may be
useful when building rich inter faces. However, in this discussion,
we will be careful not to overemphasize the UI and effect aspect of
libraries as it starts to move out of the Ajax specific realm and into
inter face design.

TABLE 5-1 Common Ajax-Focused JavaScript Librar y Features
Free download pdf