Design patterns in Javascript : Observer

This pattern also referred as publisher – subscriber pattern describes a method to allow one object to be aware of another object changes.

It allows you to ask to be notified when the state of the observed object changes, so that you can react on that information.

As you can imagine, this pattern is widely used to implement event systems.

Have you ever write Ajax code or used a call back function?

Then you have used this pattern. Continue reading

Design patterns in Javascript : Singleton

 

The singleton patterns was documented as a solution to a simple problem, “Only one object of class X can be instantiated at any time in the application”

Typically a singleton is implemented by restricting access to the class constructor, effectively making impossible to instantiate the class

It is common to use singletons for application wide configuration or database access classes.

Continue reading