understanding javascript design patterns