Section 14.1. Before Jumping In, A Word of Caution


14.1. Before Jumping In, A Word of Caution

Many of the libraries covered in this chaptermany of the Ajax libraries, periodplace some limitations on what you can and cannot do in JavaScript if you plan on incorporating them into your applications. It's important to be aware of how much of an impact they can have.

The Prototype library, the first we'll cover, is an excellent example of how much a library can affect even basic JavaScript development. At one time, it made a modification to the Array object, using that object's prototype property, that actually broke how associative arrays are manipulated when they are created using the Array object. Many Ajax developers believe that you should never create an associative array using the Array object, but instead should use the Object itself. Still, to break a built-in object such as this raised a hue and cry, and in the next version release of Prototype, this "enhancement" was removed.

However, Prototype still modifies basic JavaScript objects. After all, this is a feature of JS; expect that library developers will use it. This means you have to be aware of exactly what modifications have been made, and because many of the Ajax libraries have really poor documentation, discovering the gotchas could be a real challenge.

Another issue is event handling. Many of the libraries, such as Dojo, load functionality using the window load event. If you don't use DOM Level 2 event handling, you'll overwrite what Dojo creates and break the effects. When using an Ajax library, the best way to add a windows onload event handler is with code similar to the following:

   // test for object model    if (window.addEventListener) {       window.addEventListener("load",finish,false);    } else if (window.attachEvent) {       window.attachEvent("onload", finish);    }

In general, when working with Ajax libraries, expect to use DOM Level 2 event handling for most or all of your own efforts.

Finally, there's a feeling among many of the Ajax developers that standards and accessibility are not big issues. More than one developer has disdained the need to provide effects that validate as XHTML, even XHTML transitional, which I used in the examples in this book. However, a page that doesn't validate as XHTML also won't be accessible, and there's no way I can condone disregarding the needs for accessibility just to add some pretties. There are always valid and accessible workarounds to any worthwhile effectif you take the time to look for them, that is. In the Q & A sections at the end of the chapter, I cover one such, and once you accept that valid markup and accessible effects are achievable (and important), you'll find your own workarounds.

OK, enough of the caveatson with the show.




Learning JavaScript
Learning JavaScript, 2nd Edition
ISBN: 0596521871
EAN: 2147483647
Year: 2006
Pages: 151

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net