Review: Learning JavaScript Design Patterns

This post is more than 2 years old.

I've been thinking a lot lately about client-side development (as is hopefully evident by the type of posts I've been making). I feel like I've finally gotten comfortable with JavaScript, but am looking for ways to bring my skill set to the next level. In general, I'm looking for ways to better organize my code. I know that design patterns can help me with that goal. So I was pretty excited to get "Learning JavaScript Design Patterns" by Addy Osmani. My expectation was that this book would give me a good overview of the various types of patterns I could apply to my client-side work. Unfortunately, I don't know if the book reaches that goal. Let me explain why.

The book does a good job of introducing the concept of patterns in general, as well as explaining why classical patterns that you may have applied from a traditional object-oriented environment may not apply as well to JavaScript. These are important concepts, but I feel like the book focuses a bit too much on them. There is an even an entire chapter dedicated to writing patterns before the reader is introduced to any actual patterns. It isn't a big chapter, but I felt like so much time was spent on theory in the beginning that people who are not traditional comp-sci folks (like many web developers) may be a bit put off. Right after the chapter on writing patterns is a discussion on anti-patterns. Again, I think this is an important concept, but it just continues to delay the introduction of proper JavaScript patterns.

When the book finally does get down to business (chapter 9), the examples are both good and bad. They are good in that they demonstrate the concept at hand, but bad in that there are very few practical examples. For example, a basket module (somewhat related to a shopping cart) in the abstract isn't terribly helpful. I was really hoping to see a full, if short, web application that demonstrated the pattern in use. I know "real" applications can be difficult, but I feel like too few of the code samples actually bring the concept home for the reader. As another example, there is an entire section on jQuery Plugin design patterns. To me, that seems like such a limited audience it just adds to the 'noise' of the book.

I think this is the biggest fault of the book. If you're experienced in traditional programming, you can take the book and use it well. If you're the traditional web developer (who typically learned in bits and spurts as they had to) then it will be very difficult to take practical benefit from this book.

This is something I find in many cases throughout the web community. I feel like there's a great deal of intro material, a great deal of very high end abstract material, and very little in terms of intermediate-level discussion. It feels painful to go from Beginner to Intermediate versus Intermediate to Advanced. I'm not sure if others feel that way, but thats how it seems to me.

I think I can recommend this book if you've got some experience with patterns already, but not if you're coming from a non-CompSci (or server-side) background. I've got a great deal of respect for Addy and would recommend his blog and any presentation he gives.

For folks curious about what type of material I think does do a good job of having practical examples, I'd strongly recommend the new series by Elijah Manor: The Angry Birds of JavaScript This is exactly what I'd like to see more of!

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for HERE Technologies. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Peter Carabeo-Nieva posted on 4/15/2013 at 2:38 AM

I'm thrilled that someone of your standing in our community has come out and said all this because I couldn't agree more and it validates much of what I'd been feeling/experiencing as well...

Comment 2 by Eric Terpstra posted on 4/15/2013 at 5:01 AM

Just curious if you've also read, "JavaScript Patterns" by Stoyan Stefanov? If so, I would be very interested in how they compare, considering they are both from O'Reilly and published within a couple years of each other.

Comment 3 by Raymond Camden posted on 4/15/2013 at 5:06 AM

I have it - and read it about two years ago. I don't think I was ready for it then. I want to read it again. Currently reading "Third Party JavaScript."

Also, Addy had a nice response to this blog post. You can read it here:

https://plus.google.com/115...

Comment 4 by John Waddell posted on 4/15/2013 at 5:47 AM

I have not found this book to be of practical value for me. I've maintained more JavaScript than I've written, but I'm no novice - I'd expected something different I guess.

Comment 5 by Gary posted on 4/17/2013 at 3:41 AM

Opinions on any given JavaScript book seem to vary considerably, so while I've only read one book whole (Crockford's Javascript: The Good Parts), most would seem to have a lot to criticize. Crockford's has plenty to criticize too but its compactness made it an interesting and first book to completely read. I suppose I wasn't ready for it but it was a good choice, a good foundation, and sure made me think. I believe Crockford calls it a beginner book which is kind of funny to me.

On the topic of design patterns, I read the heralded "Design Patterns: Elements of Reusable Object-Oriented Software" shortly after it came out (many years ago now). It is definitely a book for comp-sci types (as you would say) and while that's my degree, I thought it was overrated with many tedious patterns in tough psuedocode; and not abundantly pratical. At least that's how I remember it now. However, now, the simpler patterns, at least, from the book, are well-known and muh used and it only increased in popularity. Maybe I should admit that I was wrong but I continue to think that a lot of people must have purchased it (based on glowing recommendations) that didn't get as much out it as they thought they would.

Comment 6 (In reply to #2) by Wesley posted on 11/12/2016 at 10:42 PM

I know this post is old, but hopefully this will help someone: I
borrowed and read Stoyan Stefanov's book two years ago (2014) and found
it to be excellent. I now need to read such a book again, but saw that
there was this newer one by Addy Osmani, so even though I questioned why
another book so similar would exist, I bought it, thinking it would be
better being newer. I am a very experienced JavaScript developer, but on
reading this book to refresh my knowledge of patterns, I have found it
to be terribly written. Very confusing. Many of its examples leave a lot
for the reader to work out for himself, whereas a couple of comments or
a short paragraph about the example would have made things much easier.
Not helping at all with all this is that many of the variable names and
function names in the examples are very confusing indeed. I read and
understood Stefanov's book in a very short time, because it is well
written and organised, but with Osmani's book, I've had to keep
re-reading examples and paragraphs, and even then, I've given up on
trying to understand some parts altogether. I now have to buy Stefanov's
book (which is cheaper, by the way) and I just wish I could return this
book as 'faulty' and get my money back - but how is that possible with a
book?