考虑这个简单的 JavaScript 代码 - http://jsfiddle.net/mark69_fnd/c2DRP/
使用 JSLint 验证代码会在 inner
函数内使用 this
时触发 jslint“严格违规”错误。但是,该函数是使用正确的非全局上下文调用的。
那么,我想知道如何抑制该特定函数的 JSLint 错误?
谢谢。
最佳答案
JSLint 不支持这一点,您必须忽略它。社区 fork 名为 JSHint有一个名为 validthis
的选项在像您这样的情况下,这可以抑制警告:
block 引用>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/