javascript - 如何使用 JSHint 禁用有关 'this' 和严格模式的警告?

标签 javascript angularjs jshint

我正在使用 AngularJS (v1.5) 编写一个网络应用程序,所以我有一些 Controller ,在这些 Controller 中我经常声明如下内容:

function myController($someDirectives, ...){
    var ctrl = this;
    // My code
}

问题是当我对我的代码进行 JSHint 时,我收到了针对我在 Controller 中声明的所有“this”的警告消息:

If a strict mode function is executed using function invocation, its 'this' value will be undefined.

我必须明确指出,在我的 .jshintrc 文件中,我设置了 "strict":false。 有谁知道如何特别禁用此消息?

提前致谢。

最佳答案

.jshintrc文件中设置配置

{
  "validthis": true // Tolerate using this in a non-constructor 
}

关于javascript - 如何使用 JSHint 禁用有关 'this' 和严格模式的警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42349051/

相关文章:

javascript - asi 模式下在括号前添加分号

javascript - 图像表,位于 div 下

javascript - 使用 JavaScript 检测硬重载

javascript - 在文本区域中按键提交表单

javascript - JS迭代对象数组并替换字符串中的值

javascript - ng-class 无法在 ng-include 包含在 angularJs 中的文件内工作

javascript - jshint 函数名称中带点

angularjs - 如何将参数从 AngularJS 指令传递到 AngularJS Controller 函数

visual-studio - "typescript intellisense"在我的 Razor View 中?

javascript - 一处可能存在严重违规,另一处则不然