设置控制台时JSLint:Read Only错误,即使它设置为可写全局

时间:2011-07-03 17:20:54

标签: javascript debugging jslint

请考虑以下代码:

/*global console:true */
(function () {
    "use strict";

    //set console for browsers without debugger
    if (!console) {
        console = {
            log: function() {}
        };
    }
});

这将引发错误:

Error:
Problem at line 7 character 9: Read only.

console = {

Problem at line 7 character 9: Stopping. (3% scanned).

然而,控制台已被设置为可写全局,因此它不应该只读。

有关如何规避或解决此问题的任何建议?

感谢。

2 个答案:

答案 0 :(得分:1)

我复制了你的代码并尝试进入www.jslint.com,不得不改变两件小事,但它现在没有错误(在“函数”之后添加了一个空格并添加了自我调用):

/*global console:true */
(function () {
    "use strict";

    //set console for browsers without debugger
    if (!console) {
        console = {
            log: function () {}
        };
    }
}());

你在哪里尝试过?

答案 1 :(得分:1)

如果您使用的是jslint.com网站,并且选中了Assume console, alert, ...框,请尝试取消选中该网址。