Creating Your Own Custom JavaScript Objects

In the last few chapters of the book, which cover Ajax and the various code libraries you can download, you’ll see how much improvisation was used to create objects using JavaScript. At times, these libraries look almost as if they’re built in a language other than JS. In fact, many were built specifically to overlay the JavaScript language with other language characteristics, which has both advantages and disadvantages.

An advantage is that the library provides shortcuts for some of the more tedious operations, such as accessing page elements. Laying another language’s flavor over JS may also make it easier if you use this language as the server-side component in an Ajax application.

The disadvantage is that this effort obfuscates the underlying JavaScript, making the library hard to read, hard to use, and confusing if you’re not necessarily up on all the latest language advances.

One of the best essays I’ve seen written on the ambivalence associated with some of the clever and powerful, but obscuring, component libraries is “Painless JavaScript Using Prototype” by Dan Webb at Sitepoint (at http://www.sitepoint.com/article/painless-javascript-prototype).

Tip

JavaScript-library developers just can’t seem to keep from trying to make JavaScript act like another language. The Mochikit guys want JavaScript to be Python, countless programmers have tried to make JavaScript like Java, and Prototype tries to make it like Ruby. Prototype ...

Get Learning JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.