Wednesday, August 29, 2012

JavaScript Patterns - From Padawan, to Jedi master

I recently purchased the JavaScript Patterns kindle edition written by Stoyan Stefanov. I had read his Web Performance Daybook a couple of months ago and it was a good read. So I had feeling this one's going to be worth my money.

Now it's often difficult to find good intermediate to advanced technical books that help you get over the hump. I have about read 90+ computer reference books, and this is one of my favorites. If I were to  sum up this book's review in a single line then "Each time I reread the book, I learn something new. ”

This is a nice thin book suggesting useful patterns and coding practices in Javascript. It clearly explains the occassional unexpected features of the Javascript language. If you’re looking for best practices and powerful patterns to help you write better, maintainable, robust JavaScript code, this book is for you.

What to expect from the book? (abstracts picked from book)

Some of the basics (like loops, conditionals, and closures) are not discussed at all. If you find you need to brush up on some of those topics, refer to either JavaScript: The Definitive Guide or JavaScript: The Good Parts. At the same time, some topics (such as object creation or hoisting) may look too basic to be in this book, but they are discussed from a patterns perspective and, in my opinion, are critical to harnessing the power of the language.

His chapters on Object Creation Pattern is exceptionally good where he explains namespacing, dependency declaration, module pattern, and sandbox patterns. All these help you organize and structure your application code and mitigate the effect of the implied globals. Other topics of discussion include private and privileged members, static and private static members, object constants, chaining, and one class inspired way to define constructors.

When talking about Code reuse pattern, the first thing that comes to mind is inheritance, and a great deal of his chapter is dedicated to this topic. You see several ways to do “classical” and nonclassical inheritance. But it’s important to keep the end goal in mind we want to reuse code. Inheritance is one way (means) for us to reach that goal. And it’s not the only way. The author shows how you can compose objects from other objects, how to use object mix-ins, and how you can borrow and reuse only the functionality you need without technically inheriting anything permanently.

Purchasing the Book

All-in-all, I would highly recommend this book to anyone seeking a comprehensive knowledge of JavaScript and best practices. Within a few minutes you can take your knowledge of JavaScript from intermediate to advanced. It does; however, require a good understanding of the language.