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 开发者_StackOverflow中文版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!
Peter Michaux explains Javascript namespacing very nicely.
You can have a look at this video from Google tech, which explains best practices for JavaScript coding which is a main part of Firefox extension development
http://www.youtube.com/watch?v=0LKDImgRfrg
alt text http://0.gvt0.com/ThumbnailServer2?app=vss&contentid=4d0ae57a8484fdf8&offsetms=275000&itag=w160&hl=en&sigh=GnGo87Drht4wi2JvP1L0PtvKT4M
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.
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/
精彩评论