Introduction

Introduction to the JavaScript Classic Patterns.

The Gang-of-Four patterns are referred to as the Classic patterns. Many of these are highly relevant to JavaScript, whereas others are less so.




Overview

We refer to the Gang-of-Four patterns as the Classic patterns. They were first published in 1995 which is interesting because this was the same year that JavaScript was first released. However, the two (GoF and JavaScript) did not see eye to eye for about a decade. Only when JavaScript became more popular and widely used (in particular when Web 2.0 and Ajax were all the rage) started there to be an interest in GoF and patterns in general in the JavaScript world.

The Gang of Four (GoF) patterns are generally considered the foundation for all other patterns. Many of these are relevant and applicable to JavaScript, but others less so. Why are some not relevant? It is because JavaScript is a highly flexible language which allows runtime changes of objects, including the addition, removal, and change of the object's properties and methods. This flexibility is essentially what some classic patterns are aiming for, but since this is already built into the language itself, those patterns are not relevant.

The GoF listed 23 patterns. In this section we will review each of these. Each pattern includes a description including a diagram (semi-UML), a traditional code implementation, and a JavaScript optimized code implementation. Let's get started with the first pattern which is Abstract Factory.