Review of “JavaScript Patterns”

JavaScript Patterns

Title
JavaScript Patterns
Author
Stoyan Stefanov
Rating

Writing solid JavaScript, properly explained

Master and beginner JavaScript developers alike have a reason to thank Stoyan Stefanov- he did a fantastic job surveying the JavaScript landscape and mapping out key strategies for us to use in writing JavaScript applications large and small. He explains JavaScript and how to use it properly very well in this book.

“JavaScript Patterns” is a thoughtful, thorough, and written manual on developing JavaScript applications in a patterns-based way. It excels in three main areas:

  • First, it explains with clear examples the difference between classical (e.g. class-like as in C++, Java, C#) language idioms of which many of us are indoctrinated and the more modern, functional, loose-type style of JavaScript. It is a good sell, as he argues convincingly for a more free and open understanding of what an Object can be in a Object-Orientated architecture. Most worth noting is how it so clearly explains the variety, prominence, and role of Functions in the language.

  • Second, it clearly shows through example many of the JavaScript “gotchas” like counter-intuitive hoisting rules and issues with unexpected typecasting. Each point comes with an example sophisticated enough to get the point across but without unneeded detail.

  • Finally, it dives into richer examples of the classical design patterns (Singleton, Factory, Decorator…) and how to apply them in JavaScript well using many of the OO patterns discussed earlier in the text.

High value in each Chapter

The “signal to noise” ratio in this text is very high. Very often authors, most notably Crockford, will go down a rabbit hole of pedantic unimportant threads. Stefanov keeps us on a focused course dedicating the most time to the subjects that really are core and matter in the language: Functions, Global Scope and Modules, building Objects.

The two exceptions to this are as follows:

  • His survey of Classical inheritance patterns is too involved. He spends many pages discussing the minutiae of slight differences in applying classical inheritance patterns to JavaScript, only to later argue that none of them should be used. That could have been explained to us without the long fruitless journey.

  • Some of the example Applications he uses to explain the patterns could have been refactored and simplified. Most notably his extended “Proxy” example missed the mark in trying to get the core pattern across because it was lost in too much unneeded application detail.

CoffeeScript and JavaScript

“JavaScript Patterns” is an absolute excellent text and can serve those writing server-side applications with JavaScript along with those using CoffeeScript to abbreviate the language. Even though CoffeeScript isn’t mentioned, it explains the patterns that CoffeeScript uses when it compiles to JavaScript. To better understand what CoffeeScript is doing, read this book.