views:

323

answers:

4

Hi there

I've been writing a Firefox extension, but have recently read a few articles explaining that it's bad practice to avoid variable name clashes by simple appending the application name to the front of the variable.

Unfortunately I have been doing this. What is the best practice instead? I assume it's to somehow namespace the variables. I've found various articles about wrapping everythign in a master object, but sadly no examples of this.

Can anyone point me to a good tutorial, or even a simple extension, that uses best-practices?

Thanks!

+6  A: 

Peter Michaux explains Javascript namespacing very nicely.

kangax
+6  A: 
Xinus
+2  A: 

Thanks very much for taking the time to answer - there's some useful stuff there for sure.

I also found this guide, which is pretty comprefensive:

http://robertnyman.com/2009/01/24/how-to-develop-a-firefox-extension/

Graham
+1  A: 

Not strictly related to your original question about namespacing, but https://addons.mozilla.org/en-US/developers/docs/how-to/extension-development has a link about that as well as about other extension best practices.

Nickolay