我有一个名为bbUI.js的文件,它包含了这一点JavaScript。在该文件之外,我希望能够调用“var x = new iScroll(...)”,但是我目前得到错误“ReferenceError:Can not find variable:iScroll”。访问在匿名函数中声明的函数?
(function(){
var iScroll = function (el, options) {
var that = this,
doc = document,
i;
// More code
};
})();
从我可以告诉,iScroll是一个匿名函数中定义的,而且本身匿名,但分配给该标识符iScroll。如果这是准确的,我应该能够在代码的其他地方调用“var x = new iScroll(...)”吗?
+1:从来没有想过的'window.foo'伎俩。好一个。 – Blender 2012-03-28 16:08:41