【问题标题】:Internet Explorer Function Inside a Function Does Not Work函数内部的 Internet Explorer 函数不起作用
【发布时间】:2014-12-05 06:18:39
【问题描述】:

我有那个脚本:

var information = function() {    

  this.paco= function() {  
	console.log("function called");
  };
  
  this.paco();

}();

还有这个:

var information = function() {    

  var paco= function() {  
    console.log("function called");
  };

  paco();

}();

但这有效:

var information = function() {    
...
  this.paco= function() {  
    console.log("function called");
  };

  //this.paco();
...
}();

它适用于 Firefox,但不适用于 Internet Explorer,并且不会将任何错误记录到控制台。当我尝试在information 中调用一个函数时,我得到了这个日志:

Object doesn't support this action

这里有一些信息:http://www.spilgames.com/javascript-bug-in-internet-explorer-8-and-older/ 我不能把所有的代码都放上,因为有很多脚本互相调用。有什么想法吗?

【问题讨论】:

  • 您能否提供更多上下文,并可能在每个代码 sn-p 之前说明什么有效或无效。我不清楚,因为当我在 IE 和 FF 中运行这些代码 sn-ps 时,它们都在正常工作。
  • 我已经把你的示例变成了一个 sn-p,然后我去 IE 并且它工作了......
  • 无法在 IE 8 中重现该问题。
  • 你为什么在 IEFE 中使用this?在您的实际脚本中,该属性是否也名为 paco
  • 这两个函数都没有返回语句,所以它们返回undefined,所以information的值为undefined

标签: javascript internet-explorer internet-explorer-9


【解决方案1】:

我找到了原因。那是因为

console.log("function called");

它不适用于 Internet Explorer 9。这里有一个解释:Does IE9 support console.log, and is it a real function?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-21
    • 1970-01-01
    • 1970-01-01
    • 2012-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多