X

Javascript Patterns: Review

javascript patterns

Over the holidays I read Javascript Patterns by Stoyan Stefanov.
Its a pretty light book consisting only of 240 pages, which is light in computer reading, where majority of the books are like yellow pages phone book over 1000 pages. It was quite enjoyable to have a concise book written by Stefanov, another highly recommended book is his Object Oriented Javascript.

Anywayz here is the low down.

Chapter 1. Introduction
This chapter is more of an introduction of using firebug (console.log), jslint, object orientation and prototypes in javascript.

Chapter 2 Essentials
This chapter talks about styles and coding standards, a must read for anyone doing javascript, patterns consisting of the single var variable and minimizing global variables, commenting code, api’s etc

Chapter 3 Literals and Constructors
Its about object literal notation, constructors functions using new, array notations, json, regular expressions and build in types e.g Error consturctor.

Chapter 4 Functions
Contains an indepth use of functions in javascript as first class objects, topics covered were API Patterns (Callback, Configuration objects, returning functions and currying), Initialization patterns (immediate functions, immediate object initalization, init-time branching) and last Performance patterns (Memorization and self-defining functions)

Chapter 5 Object Creation Patterns
One learns about the namespacing pattens, declaring dependencies, private, privileged method. The module patterns, sandbox pattern and last the object constants, static methods, chaining and lastly the method() method.

Chapter 6 Code Reuse Patterns
This chapter talks about inheritance by using borrowing methods, copying properties and mixin in javascript, it also covers classical inheritance but how there are more elegant ways in javascript rather than using the classical way.

Chapter 7 Design Patterns
This chapter goes through 9 GoF patterns and how to implement them in javascript namely Singleton, Factory, Iterator, Decorator, Strategy, Facade, Mediator, Proxy and lastly Observer. The author goes about to show how one can create these patterns in javascript in various ways, it takes a different mind set then the GoF book since javascript is dynamic and functions are first class (GoF was C++ examples in static languagues), if you are a GoF head u should read this chapter.

Chapter 8 DOM and Browser Patterns
The last chapter talks about using javascript in the browser, the author uses mostly YUI, although most of the things covered are already in jquery built in, I wish he covered more on jquery but ohh well. The bonus is he talks about loading javascript how to lazy load script tags and using setTimeOut for long running operations.

Conclusion
All in all I would definitely recommend this book, its not really a beginner book but if you are doing javascript its a definite read.

As I was writing this and finishing up the blog I also saw elegant code has posted a very good review of this books on their blog.

Categories: Books javascript
Taswar Bhatti:
Related Post