Some common design patterns using JavaScript