Jump to ratings and reviews
Rate this book

JavaScript Patterns: Build Better Applications with Coding and Design Patterns

Rate this book
What's the best approach for developing an application with JavaScript? This book helps you answer that question with numerous JavaScript coding patterns and best practices. If you're an experienced developer looking to solve problems related to objects, functions, inheritance, and other language-specific categories, the abstractions and code templates in this guide are ideal―whether you're using JavaScript to write a client-side, server-side, or desktop application. Written by JavaScript expert Stoyan Stefanov―Senior Yahoo! Technical and architect of YSlow 2.0, the web page performance optimization tool― JavaScript Patterns includes practical advice for implementing each pattern discussed, along with several hands-on examples. You'll also learn about common programming approaches that cause more problems than they solve.

216 pages, Paperback

First published September 1, 2010

225 people are currently reading
2352 people want to read

About the author

Stoyan Stefanov

23 books70 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
664 (40%)
4 stars
649 (39%)
3 stars
255 (15%)
2 stars
51 (3%)
1 star
10 (<1%)
Displaying 1 - 30 of 73 reviews
Profile Image for Rob.
Author 2 books435 followers
December 6, 2010
If you're a JavaScript developer, you would be wise to have this on your bookshelf--nestled nicely between JavaScript: The Good Parts and High Performance JavaScript . The three make a nice little troika.

And read them in that order: The Good Parts, Patterns, and then High Performance.

Here's why:

What Stefanov gives us with this book is effectively an overview [†] of best practices for JavaScript development, going over the benefits and gotchas of certain important language features, and translating those into design and implementation patterns. Many of these patterns are language-agnostic--and you're likely to recognize them from "The Gang of Four"--but Stefanov puts them in their JavaScript party dresses and takes them out to the ball. Wisely, Stefanov also presents these patterns in an environment/host-independent fashion, so the lessons you learn about encapsulation or inheritance or performance should be equally valid regardless of whether you're coding for the browser [‡] or NodeJS or some image exporting automation for Adobe Illustrator. Stefanov is also a lucid and concise author, clearly illustrating his points about these design patterns; the text is accessible--easy to follow and digest--and he is careful to clearly define words and terms that might be ambiguous or commonly misunderstood (e.g., "function expression" vs. "function declaration" vs. "function literal").

JavaScript patterns makes a great transition guide for intermediate developers--the men and women who have stopped confusing jQuery-the-library with JavaScript-the-language--the folks who are ready to re-evaluate their approach software development with JavaScript. This is for the folks that made it through Crockford's The Good Parts knowing that they learned something but also feeling less-than-certain about how to apply that something. This is the follow-on; JavaScript Patterns is the application of those lessons. And then after you've written your clean, maintainable, scalable applications--then you make the jump to Zakas' High Performance JavaScript to tune things just a little bit further.

So you're probably wondering then: if you recommend it so highly, why only four stars?

The four stars comes mostly from two niggling points:

(1) Relative to The Good Parts and High Performance, JavaScript Patterns was not published in the order that I recommend reading them. As a consequence, since I'd read the others (and quite a few others above and beyond those two), there is quite a bit of information in there that I'd seen before. This is not a Bad Thing; sometimes it pays to see information presented again--to help it sink in or else to gain another perspective on it. And in some cases Stefanov offers an as-good-or-better explanation on certain topics/techniques as others writing in the field (e.g., his examples for memoization and currying rival Crockford's, and his explanation of the pub/sub pattern (and custom event design) is more concise than the one Zakas presents in Professional JavaScript for Web Developers ). Sometimes (and I've written this before) you were just hoping for... just a little bit more.

(2) And this is super nit-picky but... The book could have taken another quick editorial pass for spelling and grammar. The one that stuck out at me was right in the intro to Chapter 6: "But it's important to keep the end goal in mind--we want to reuse cod;." Indeed.

---

† : An in-depth overview, but an overview nonetheless.

‡ : Stefanov is careful to "keep the browser out of it" and dedicates only one chapter (Chapter 8: DOM and Browser Patterns) to the subject; though everyone's favorite host environment does creep in a couple of times, in a couple of examples.
Author 1 book7 followers
December 24, 2016
This is a good book and most people who work with Javascript should spend at least a couple hours going through it. But there is a caveat: it is old.

This book was published in 2010, and there are many things that are talked about, which we really don't have to worry about anymore. In this book, there are many IIFE examples that are no longer needed in the world of ES2015 and beyond (i.e. ESNEXT).

In any case, you need to read through this book in a smart manner. Don't force yourself to go through absolutely everything, and definitely skip some sections if it's quite obvious that you won't really need to go through them in detail since a lot of today's best practices avoid some of the mentioned patterns completely.

Nevertheless, this is an important book to read. And if you have a nuanced reading strategy (like I mentioned above), you can probably get through this book within 3 hours or so and learn a decent amount while doing so.
Profile Image for Petar Ivanov.
85 reviews42 followers
August 19, 2020
Really great book about some more advanced JavaScript concepts. There are a lot of examples and good explanations. It's not for beginners but it's very helpful for people who want to dig deep into the language. Recommend it to every JS software craftsman!
Profile Image for Rod Hilton.
152 reviews3,116 followers
July 6, 2011
JavaScript Patterns was the first book that made me feel like I really *GOT* JavaScript. I've come away with a much greater appreciation for the language than I used to have, and I feel much more comfortable with the idiotmatic usage of the language.

The book, written by a Senior Yahoo! programmer, is more than just a "here is how to do the XYZ Design Pattern from the GOF book in JS" (though it has quite a bit of that at the end). It's really a book about patterns that have evolved out of JavaScript's usage - these are *NEW* Patterns, that are specific to JavaScript, which the author has observed and annotated. As the GOF book was to Object Oriented languages, JavaScript Patterns is to JavaScript.

The book covers a lot of ground, helping the reader understand not only the what, but the why of various JavaScript conventions. It is very well written and always interesting - if I didn't have to occasionally take breaks to avoid melting my brain, I'd have been virtually unable to put it down.

I'd say that if you're a web programmer and you want to take your JavaScript up to the next level, you should read The Good Parts, High Performance JavaScript, and this book. It was an eye-opener for me, and I highly recommend it.
Profile Image for Greenicicle.
27 reviews
April 5, 2011
So far I'm a little disappointed that practices like "write sensible comments" and "indent properly" are really listed as patterns, especially when the book claims to be targeted to professional devs. But I've still got a bunch of pages to go through.

UPDATE: Finished now. The title does not lie: the book is full of patterns. There is a focus on organizational patterns (object creation, inhheritance). Of these, there is a large variety of variants; mostly presented in an evolutionary chain the leads to increasingly better solutions. This is interesting for a an understanding why a pattern in recommended, it's not the most compact way of representation on the other hand.

There is a lack of macroscopic, task-oriented patterns. This is not a book learning about common patterns in general, applied to JavaScript.

I found reading JavaScript patterns beneficial; coming from C# as my primary language it filled some of the gaps on how objects and funtions can be utilized to create a richer programming platform. For that purpose however, I found "The Good Parts" more compact.
600 reviews11 followers
March 24, 2014
Only a small part of JavaScript Patterns is about design patterns. Much more pages are spent on best practices and the deployment story. While these parts are very useful, they may not be what you are looking for.
The Singleton pattern is a one example I like to pick to illustrate some of the problems with the book. In books about design patterns for other languages like Ruby that doesn’t have the concept of a Singleton, the explanation of the pattern is simply: Not supported here. In his book Stoyan Stefanov keeps going and going and uses 5 pages with workarounds. This is great if you must implement a Singleton, but most likely you are better off if you just would stop forcing it into JavaScript.
As long as you read this book as a way to write JavaScript and not as the definitive guide on JavaScript Patterns you can learn a lot.
Profile Image for Diego Higuchi.
12 reviews1 follower
October 29, 2014
Este livro me proporcionou maiores conhecimentos de padrões de projeto (Singleton, Factory, Iterator, Decorator, Strategy, Façade, Proxy, Mediator, Observer), performance javascript entre outros, como pude aprender também o que são anti-padrões. O livro cita exemplos primeiramente como "não fazer" e como "fazer" (anti-padrão e padrão), bastante objetivo. Recomendo à todos desenvolvedores.
34 reviews2 followers
Currently reading
August 14, 2012
Learning a lot of stuff from this book. Very interesting and very useful.
Profile Image for Emre Ergin.
Author 10 books83 followers
August 5, 2022
Apparently books getting obsolete this fast is a common pattern in programming. However, since this book tried to explain what we are solving properly, so I know what the code is trying to evade, I could check myself whether or not those limitations of JavaScript is still around, and if so, took a mental note.

The way that the author approaches the issue is so elegant and clean, and I tried to focus his problem solving style rather than actual functions, patterns used, so I learned a lot.

My main gripe was the focus on some then probably popular libraries like Yahoo's YUI and such. Nothing the author could something do about of course.

I still do not recommend reading this book to newbie developers since apparently Design Patterns and by extension Object Oriented Paradigm is losing its steam in the world of JavaScript, and one should learn these only sporadically.
3 reviews
August 27, 2023
The books hasn't aged well. Only a couple of chapters can be of any use in 2023. There are useful considerations to know and remember, however there are books that have better value for the time spent. If you deal with 15-years old legacy systems, then it is a great resource of patterns applied at that time.

For me personally, it was an interesting trip back to the days when I was just starting with programming and JavaScript was full of prototype patching, jQuery, Mootools, etc.
Profile Image for Sridhar Raj Sampath Kumar.
11 reviews1 follower
November 23, 2020
The book is comprehensive in terms of patterns and examples. Though some portion of it is outdated, still you'll have something to learn in terms of how they addressed the design problems prior to ES2016.
Profile Image for Harvey.
Author 1 book3 followers
September 9, 2017
Some of the author's suggestions about how to handle loading of JS are getting quite dated, but the discussion of design patterns is still worth buying this book.
Profile Image for Ros.
68 reviews32 followers
September 5, 2019
Книжка дуже крута, як на час своєї публікації. Но відразу стала морально застаріла після виходу ES6ю
Хоча є розділи які і зараз доволі актуальні...
Profile Image for Mohammad Elsheimy.
46 reviews8 followers
August 13, 2021
This is certainly not for beginners or intermediate developers. This will help you implement various design patterns using JavaScript. It will make you think twice before writing code :-)
Profile Image for Dave Lorentz.
1 review
December 8, 2017
Do not re invent the wheel! Patterns are a cornerstone of systems design and this book shows how they can be applied. I would like to see data access patterns added, especially now that HTML5 is so wide spread. But that does not take away from the good set of patterns described here.
Profile Image for Marcus.
520 reviews48 followers
March 19, 2016
Let me start by presenting my 'credentials' in the field - I have two decades of programming experience in different object-oriented languages, mainly in .NET platform and SQL. Most of the time I deal with client-server applications in Windows environment. Over last couple of years I started increasingly dabbling with HTML5 and JavaScript, a challenge which I admit freely is not very enjoyable to me mostly due to JavaScript's chaotic nature (in my opinion at least).
When I reached for this particular volume, I hoped it would expand my basic understanding of JavaScript and make my transition from object-oriented world into function-based programming a bit easier. This initial objective wasn't reached, for a very simple reason - 'JavaScript Patterns' is a book that tells you 'what and how', but not 'why and when'. Also, it assumes a deeper understanding of JavaScript as a language that I posess after two years of its use. I don't think it's fair to blame the book for not being what I hoped for it to be. But at the same time I must say that the presentations of different patterns in this book are really very brief and shallow. The coverage of modules in particular was in my opinion deeply disapointing - a couple of generic code snippets and references to patterns previously discussed was deeply unsatisfactory coverage of this fundamental pattern to me.
Don't get me wrong, I understand perfectly the reason this book is presented in this way - the reader is supposed to take what's shown in the book, apply it to the real life program and build on his own from there. Fine, I get it. But the briefness of the 'demonstrations' in this particular book means that the reader will have to do a lot of guesswork and probably find additional sources of information BEFORE understanding a particular technique and isn't providing this understanding the actual goal of this book? Would it be so hard for the author to expand his examples, perhaps apply the techniques he discusses to a couple of commonly occuring real life problems?
It may be the briefness of content of this book, it may be my lacking knowledge of more complex aspects of function-based programming in general and JavaScript in particular. Whatever the reason may by, I didn't find this book very informative.
Profile Image for Daniel R..
219 reviews13 followers
February 26, 2012
A grab bag of practices and techniques for JavaScript development for the core language and some browser specific concerns. The Essentials, Literals and Constructors, Functions, Object Creation Patterns, and Code Reuse Patterns chapters mostly rehash material from "JavaScript: The Good Parts". The author provides additional exposition on the concepts but doesn't introduce much new material. The Design Patterns chapter includes some good examples of JavaScript implementations but accurately points out many already exist in third party libraries. The DOM and Browser Patterns chapter provides a brief introduction to browser specific concepts and concerns but you'll want to consult the referenced books for more detailed discussions. This book is a great primer for JavaScript development due to the breadth of topics is covers but is worth a pass if you've already read other JavaScript books covering these topics.
Profile Image for David.
92 reviews5 followers
January 8, 2013
This book covers a lot of different patterns, and is a useful tour. Even experienced programmers will likely learn patterns they haven't seen before. The author's commentary is thoughtful and helps the reader evaluate pros and cons, though I think the author is not sufficiently critical of weaker techniques. Many of them are fine for small programs but don't scale well for larger ones (i.e., are not very maintainable or extensible or automatically checkable).

The bigger problem is that, like JavaScript itself, there's no remotely complete, coherent set of patterns. Many of the techniques presented don't work well together, and many problems have three or four half-solutions, each with important drawbacks. So while the book covers a wide breadth with useful analysis, the result is very unsatisfying.
Profile Image for Ryan Boone.
15 reviews5 followers
February 28, 2015
Crucial source for JS developers

JS Patterns is a well-thought out and executed resource that introduces and explains many common, helpful patterns that modern-day web and app developers will find invaluable. Stefanov clearly explains the reasoning behind each pattern, common problems they solve, as well as usage examples and source code. This book is legendary among the JS community, and it's not hard to see why. I only wish this were more updated.

I would love to see some ES6 implementations, and there are quite a few workarounds for some older browsers (though, that's something that every good dev needs to learn).

I highly recommend this book to people who have a firm grasp on JS. If you're just starting out, check out Eloquent JavaScript, then get this book.
Profile Image for Sergiu Ciumac.
14 reviews1 follower
November 26, 2012
Nicely written book. Though, I would not consider programming JavaScript using practices and patterns from OOP. I find it as an overkill implementing Object Oriented patters in a language which was designed as an event-driven, and does not support the concept of classes. Moreover, I would consider this as an anti-pattern, as it introduces a lot of misconception and non-intuitive constructs.
Overall, it brought some interesting points about JS, though a lot of them are not useful.
Profile Image for ifknot.
12 reviews4 followers
April 6, 2016
A good compliment to Crockford's book if a little less opinionated, and less entertaining as a consequence. Having been convinced by Crockford that Javascript is a different, functional language it is a bit surprising to then have Stefanov use a lot of space to show how to bend Javascript to mimic the traditional class based OOP model. The remainder is good and the patterns implementations useful but for the Singleton pattern - which, for many, is now regarded as an anti-pattern.
Profile Image for Anton Antonov.
350 reviews48 followers
October 23, 2016
Good JS design patterns book.

Before Addy Osmani's JS Design Patterns book, this book was my go-to choice.

The reason why I give it a 4/5 is that it's not as accessible as Addy Osmani's.

It starts as an uphill battle for newer JS developers looking into design patterns and some concepts are harder to get than in the later book.

Still a solid design patterns resource and definitely a go-to choice for people that are more experienced.
Profile Image for Dmitry Petrov.
10 reviews2 followers
March 9, 2016
The book introduces common solutions of problems that come into the view of every javascript developer starting from the code style and ending with realization of some OOP patterns. Information is not outdated and "JS patterns" will be a good choice if you do not need another language syntax description but want to figure out, how it works in the real world.
Profile Image for Wout Mertens.
8 reviews
August 8, 2011
In-depth review of patterns you'll need or encounter while writing JavaScript code. All patterns are clearly explained so that you understand their reason for existence as well as how to apply them yourself.

It's rather dry though, and expects a moderate familiarity with JavaScript so it should not be the first book you read when learning JavaScript.
Displaying 1 - 30 of 73 reviews

Can't find what you're looking for?

Get help and learn more about the design.