Design patterns applied to Javascript