0
我有一个JavaScript函数,它看起来是这样的:使对象非全局中的JavaScript
foo=function(listenerObject)
{
a={count:0};
foo2=function(){
//does stuff with a
}
//register listenerObject to callback the function foo2
}
问题是,我最终会使用这个函数来注册多个监听器,但他们都最终共享相同的“一个对象。有没有办法让函数内部的对象声明进入全局范围。 换句话说,我想阻止能够做这样的事
fun=function(){o={count:0}}
o.count++//o is now in the global scope