调用全局对象方法结果为null或不是IE8中的对象

时间:2012-08-16 19:35:52

标签: javascript cross-browser

我有以下JS,当它在IE8中运行时,我收到错误:ILL.TEST is null or not an object,它可以在其他浏览器上运行。知道为什么会这样吗?提前感谢您的帮助。

 //global name space
 var ILL={};

 ILL.TEST=(function(){
     function init(){
      }
     return { 
        init:init 
     };
 })();

 (function(){
      //error ILL.TEST is null or not an object
      ILL.TEST.init();
 })()

1 个答案:

答案 0 :(得分:0)

问题是我在调用ILL.TEST后定义它。所以这将是一个问题:

 //global name space
 var ILL={};

 (function(){
    //error ILL.TEST is null or not an object
     ILL.TEST.init();
 })()

 //defining after this fn is called will result in null or not an object in IE8
 ILL.TEST=(function(){
     function init(){
      }
     return { 
       init:init 
     };
 })();
相关问题