什么会导致 "Message: 'console' is undefined" 错误突然出现?

What would cause a "Message: 'console' is undefined" error to arise all of a sudden?

我已经 运行 我的 Sharepoint 网页很长时间了,没有任何问题(好吧,不是 这个 问题),今天我得到了:

Message: 'console' is undefined
Line: 1124

注意:此问题在 IE 中出现,但在 Chrome 中未出现。在IE中,Browser Mode为IE 8;文档模式为 IE 8 标准(页面默认)

第 1124 行是下面的 "console.log()" 行:

$(document).ready(function () {
    console.log('The ready function has been reached'); 
});

我找到了这个 here 的解决方案。

windowskm 在 kennytm 的回答下方的评论说,“将 if (!window.console) console = {log: function() {}}; 放在页面顶部!"

我这样做了,错误消失了。但我想知道为什么 如何 这个问题突然出现 "out of the murky grey sky" (当我输入这个时,圣克鲁斯正在下雨) - 这不仅仅是学术上的好奇心,但我'我想知道导致该问题的原因是否也对我需要注意的其他地方产生了一些尚未发现的有害影响。

IOW,使用上面的解决方案解决了一个问题,但是我需要根除更深层次的东西吗?

如果在开发者工具未打开时调用 console.log,IE 8 将始终抛出该错误。

本质上,对于 IE 8,它是一个空引用,直到控制台打开。