问题描述
我已经写了一个Firefox扩展,但最近读了一些文章,解释了通过简单地将应用程序名称附加到变量的前面来避免变量名称冲突的做法是不正确的。不幸的是我一直在这样做。最好的做法是什么?我认为这是以某种方式命名空间的变量。我发现了各种关于在主对象中包装everythign的文章,但可悲的是没有这样的例子。
任何人都可以指向我一个很好的教程,甚至是一个简单的扩展,使用最佳做法?
谢谢!
Peter Michaux 。
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!
Peter Michaux explains Javascript namespacing very nicely.
这篇关于Firefox扩展 - 最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!