javascript - 抑制 JSLint 严格违规,以便在使用正确上下文调用的内部函数中使用 this

标签 javascript jslint

考虑这个简单的 JavaScript 代码 - http://jsfiddle.net/mark69_fnd/c2DRP/

使用 JSLint 验证代码会在 inner 函数内使用 this 时触发 jslint“严格违规”错误。但是,该函数是使用正确的非全局上下文调用的。

那么,我想知道如何抑制该特定函数的 JSLint 错误?

谢谢。

最佳答案

JSLint 不支持这一点,您必须忽略它。社区 fork 名为 JSHint有一个名为 validthis 的选项在像您这样的情况下,这可以抑制警告:

This option suppresses warnings about possible strict violations when the code is running in strict mode and you use this in a non-constructor function. You should use this option—in a function scope only—when you are positive that your use of this is valid in the strict mode (for example, if you call your function using Function.call).

关于javascript - 抑制 JSLint 严格违规,以便在使用正确上下文调用的内部函数中使用 this,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12552644/

相关文章:

javascript - JavaScript 中关键字 'new' 有什么副作用?

javascript - 使用javascript更改对象数组中的键值?

c# - javascript google Places 在 html 中工作,但在 asp 内容中不起作用

javascript - 如何使用 ASP.NET 复选框和 javascript 切换属性?

javascript - JSLint "disallow insecure in regex"选项的用途

javascript - JSLint:需要一个标识符,但看到的是 'class'(保留字)

javascript - 错误: jslint gives me error here for bad looping

javascript - 有必要用 JavaScript 重写 C# 类吗?

javascript - 如果我想创建一个 AJAX 聊天,应该使用什么通信技术来保持可扩展性?

javascript - jslint 中出现意外的 '++'