Chapter 11. Creating Custom JavaScript Objects


JavaScript is a wonderfully chaotic language. Some would say this is a good thing; others would say it's the biggest detriment to its useso much so that there's a move to a new version of JavaScript, JavaScript 2.0, in order to tighten up some of the language's looser aspects. Proponents of a newer version say it's important to do so if JavaScript is to scale and be able to meet increasing demands.

After working with the previous examples, you might be scratching your head over the concept of JavaScript scaling. After all, the script tag is one of the most common found in web pages, and most sites use some form of JS. Any site that offers a shopping cart or other interactive element most likely uses JavaScript. Considering all of this, what could possibly be driving the concern about JavaScript and scaling?

The answer to that questioncreating libraries of custom objectsis the core of this chapter. The new interest in Ajax and a renewed interest in Dynamic HTML has led to a growing number of fairly large JS libraries and even larger web-based applications, so it appears that scaling really has become an issue of concern.

Or does it? After all, most of us aren't going to be creating Ajax-based replacements for Microsoft Word or Adobe Photoshop. Most of what we need are smaller libraries of objects that manage some of the more esoteric elements of Ajaxian server-side access or DHTML's more complex effects.

It is an ongoing debate, and one that is taking place at the same time as efforts for JS 2.0 are progressing. At the heart of the debate are concerns about packaging, versioning, scope, collection generation and iteration, extensions, and most specifically, how objects are defined in JavaScript. For all that makes JavaScript an object-oriented language, it lacks one thing common to most OO implementations: it doesn't use classes.

I must admit to being one of those who appreciates how simple and straightforward JavaScript is to use despite its chaotic reputation. However, I can also understand the concerns of scaling. A bigger concern I have is whether this move to a newer, better JavaScript will lead to another decade of proprietary extensions and cross-browser differences. That's the type of chaos I could do without.





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