Fellow Yahoo Ross Harmes and former Yahoo Dustin Diaz recently released their first book, Pro JavaScript Design Patterns. Since they were kind enough to drop a copy by my cube, complete with autographs, I feel like I need to at least mention the book here. So I figured I might as well give an honest-to-goodness review with no punches pulled.

The focus of the book is on implementing design patterns in JavaScript. In the professionalization of JavaScript, design patterns is a topic that has only recently been discussed, which makes this book timely. Ross and Dustin discuss most of the traditional design patterns including facade, command, decorator, adapter, observer, and many more.

The book is full of code samples that borrow heavily from YUI both in concept and source code, though I wish the attribution was a little more transparent in some places. Still, it shows just how design-pattern centric YUI and other libraries are, which is an important point to make.

One of the things I didn’t like about the book was the attempt to force the interface pattern into JavaScript. JavaScript is, by its nature, interface-less. The approach taken is unique though I feel like it’s a bit forced to make the point. Interfaces in JavaScript can never be strictly enforced and I don’t see much benefit to making the attempt. Capability detection, checking to see if a function exists before using it, is about as close to the interface pattern as JavaScript gets and probably about as close as it needs to be.

This book also suffers from a common problem among design pattern books: sometimes two patterns are so similar that it’s hard to determine when to use one over the other. Is it a facade or an adapter? The line is incredibly thin between the two. I would have liked to have seen a final summation chapter that listed each pattern including indications, contraindications, and related patterns. Ross and Dustin do make some attempts at comparing certain patterns in the book, I just would have liked to see such comparisons called out more strongly.

Don’t get me wrong, I think Pro JavaScript Design Patterns makes a good addition to your JavaScript book library. It presumes that you already have some JavaScript knowledge, so it’s not really a book for absolute beginners. You’d be well-served to pick up a book on the basics first (I can suggest a good one…hehe) and then move onto this one. I like Pro JavaScript Design Patterns because it picks up where most JavaScript books leave off. This is your first step in moving from coding JavaScript solutions to designing them. Moving forward, being able to architect a front end solution is something that will be in more demand, and this book will help you think about making your code extensible, reusable, and maintainable.

Disclaimer: Any viewpoints and opinions expressed in this article are those of Nicholas C. Zakas and do not, in any way, reflect those of my employer, my colleagues, Wrox Publishing, O'Reilly Publishing, or anyone else. I speak only for myself, not for them.

Both comments and pings are currently closed.