Pro JavaScript Techniques

Pro JavaScript Techniques

Got something to say?

Share your comments on this topic with other web professionals

In: Reviews > Book Reviews

By Matthew Pennell

Published on December 26, 2006

Book cover: Pro JavaScript TechniquesAnyone writing JavaScript over the last year is likely to have at least a passing interest in the many and varied libraries that have sprung up in that time, and—if you fall into that category—you have probably heard the name of John Resig.

As author of the jQuery library, Resig has demonstrated his skill at abstracting and simplifying JavaScript functionality while keeping the code understandable. In this, his first book, he shares some of his knowledge and professional techniques, and the result is an engaging and illuminating volume that well deserves its place on any JavaScript author’s bookshelf.

Who is the book for?

If you’re looking for a book suitable for the absolute beginner, stop reading now: This is not that book. There is no preamble on the founding fathers of web standards here, no lectures on semantic HTML and valid CSS, and no introductory ’Hello World’; barely two paragraphs into Chapter One and we’re straight into object-oriented JavaScript, testing, and packaging scripts for deployment. Before the end of the second chapter, you’ll have covered references, scope, closures, and context; old news for those schooled in languages such as Java, Perl or .NET, but it is refreshing to see OO concepts covered in such a comprehensive, understandable way in a commercial JavaScript book.

However, if you are still writing repetitive, procedural code—or perhaps you’re surviving the object-oriented world through trial-and-error, not quite understanding the underlying concepts—then Resig’s clear explanations and examples will set you on the path to writing professional-standard JavaScript. As he says at the end of Chapter Two, “Simply understanding how objects act, references are handled, and scope is decided can unquestionably change how you write JavaScript code.”

What will I learn?

In addition to the comprehensive introduction to object-orientation, Resig does well to cover concepts that sometimes feel a little ignored in other books on the subject. There is a simple, understandable explanation of event bubbling (which I’ve never seen explained clearly anywhere else) and how to treat the event object, different ways to approach packaging your code, and tips on code validation and compression.

He also does a nifty line in recursive functions—in fact, the book is littered with generous amounts of helper functions (some of which may be familiar to users of the jQuery library), providing convenient shortcuts to common functionality.

The latter half of the book is taken up with real-world examples of functionality in action, all clearly explained (although it might be nice if just for once a JS book didn’t feel the need to include an image gallery script). The AJAX example in particular is very thorough.

Begin again

Reaching the middle of the book, I was left with the curious feeling that I had been reading it backwards. From the initial leap into the deep-end of object-oriented code, packaging, and all the rest, the central chapters slow right down for a leisurely look at navigating and manipulating the DOM, and event registration. Considering that anyone in need of this relatively basic level of knowledge would have given up reading long ago, the chapter ordering does seem a little strange, although there are some simple but useful functions to aid DOM navigation that rescue the chapter from a complete glossing over.

There are also a couple of other sections that I felt were a little rushed. While an entire chapter is dedicated to debugging and testing, the individual browser extensions and unit-testing tools mentioned each receive only a brief summary, even though Resig later states, “Having a test suite for your code is far too important a topic to ignore.” The chapter on using JavaScript with CSS also lacks the clarity of some of the earlier sections, and a couple of the functions are, to my mind, missing clear explanations for the choices that were made.


The book closes with three appendices, including a handy reference for all things relating to event detection and handling.

To his credit, Resig only mentions jQuery three times, and always in conjunction with other libraries. In the end, rather than what could have been a promotional piece, you are instead left with one of the most thorough and well-written books for truly professional JavaScript authors.

Related Topics: DOM, Scripting, Programming

Matthew Pennell works as a senior designer for one of Europe’s leading hotel booking websites, writing semantic XHTML, bleeding-edge CSS and JavaScript that usually works. He is the former Managing Editor and former Editor in Chief of Digital Web, and blogs at The Watchmaker Project.