jQuery:全局变量命名空间问题 [英] jQuery: Global Variable Namespace Problem
问题描述
是否可以在jQuery中以自己的名称空间声明全局变量?
Is there a way to declare a global variable in jQuery in its own namespace?
当然,我可以使用普通的旧JavaScript声明全局变量,但是它们将属于window
的命名空间.例如,如果我有一个名为document
的变量,它肯定会覆盖window
的document
对象.
Sure, I can declare global variables with plain old JavaScript, but they will fall in the window
's namespace. For example, if I had a variable named document
, it would surely overwrite the document
object of the window
.
jQuery是否有一个哈希表,可让您按对象名称存储任何对象?
Does jQuery have a hash table that lets you store any object by their name?
谢谢.
推荐答案
不确定为什么要使用jQuery吗?您可以创建自己的名称空间:
Not sure why you want to use jQuery for that? You could just create your own namespace:
var namespace = {
document : "Foo"
};
如果需要以某种方式使用jQuery,请详细说明.
Please elaborate, if there's some need to use jQuery somehow.
这篇关于jQuery:全局变量命名空间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!