Relevance Reviews #1: The JavaScript Anthology

My in-plane reading for the NFJS Omaha trip was the recently published JavaScript Anthology from SitePoint. I picked up a copy specifically looking for resources to recommend to Ajax developers.

There is a lot to like about this book:

  • The authors clearly know their stuff, and in detail. Everything is demonstrated with code.
  • The individual tips are well-organized, with a statement of the problem, solution, and discussion. I found the format easy to skim (for stuff I already basically knew), and easy to dive in where necessary.
  • The authors provide lots of links to additional resources.

More than half of the book is devoted to effectively using the APIs that are present in a modern web browser, for manipulating the Document Object Model, forms, windows, ranges, DHTML, CSS, XHR, etc. These items will be of great value to anybody who has to write effective JavaScript in the face of browser variabilities. Most of the tips are captured as JavaScript procedures which you can easily adapt for your own programs.

Relatively less time is spent on the language itself--the intro chapter, plus concluding chapters on OO and performance. While these chapters are reasonable as far as they go, I wish they went a lot farther. Like most authors writing about JavaScript, the authors sound a bit apologetic in comparing JavaScript's prototype-based inheritance to class-based OO. There's no need to apologize! JavaScript provides very powerful abstractions. The best Ajax developers are embracing these abstractions, without constantly looking in the rear-view mirror at classes.

The most troubling part of the book, particularly for an Ajax developer, is the disconnect between the "procedural" style of most of the sample code, and the object-based (and functional) style of JavaScript you will see in libraries such as Prototype. Hidden in the Ajax wave is a set of programming techniques which go far beyond Ajax in their utility and importance:

  • closures
  • internal iterators
  • metaprogramming
  • AOP
  • Duck Typing
  • Functional Programming
You won't find much on these topics here. In fairness, I am not aware of any JavaScript book that hits these. Your best bet for today would probably be to learn Ruby and transpose Ruby->JavaScript in your mind.

To sum up, this is a well-organized, solid book. It will be most useful for people writing and supporting "raw" JavaScript. Most Ajax developers should be using libraries to handle much of this low-level detail. That said, you always need solid knowledge of at least one level of abstraction beneath the one where you are working. Read the JavaScript Anthology to learn that next level down, and stay tuned for future reviews where I'll cover some books that target Ajax more directly.