Basic JavaScript widgets bound to one namespace
I often have the same basic widgets in each application that I work on; some kind of loader, maybe a noticer, custom confirm dialog and so on. At first, I always had a global variable for each widget, making them accessible from any place in the code. But as the application grew, so did the number of widgets, leaving me with a rather polluted global namespace. To avoid this I now always use a basic object to create a namespace, where I reference further to each widget. Example:
Instead of having a global variable for each widget, there is only one, the mighty app. They're still accessible from anywhere though:
This can be expanded a lot, as discussed in a great post by Aaron Newton: http://www.clientcide.com/best-practices/singletons-and-event-arbiters/
Comments [0]