运行以下简单代码会导致“严重违规”。错误信息。我一直在尝试查找有关原因以及如何修复它的文档。任何输入将不胜感激。
错误:
Error:
Problem at line 6 character 4: Strict violation.
} (this));
示例代码:
/*jslint browser: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, strict: true, newcap: true, immed: true */
"use strict";
(function (window) {
} (this));
问候,埃吉尔。
最佳答案
扩展 Roland Illig 的回答:
在非严格模式下,this
在未绑定(bind)到任何其他内容时绑定(bind)到全局范围。在严格模式下,它是未定义的。这使得在方法之外使用它是错误的。
关于javascript - jslint:为什么此代码会导致 "Strict violation"错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2500512/