I am writing a web app using AngularJS (v1.5) so I have some controllers, and in those controllers I am often declaring something like :
我正在用AngularJS (v1.5)编写一个web应用程序,所以我有一些控制器,在这些控制器中,我经常声明如下内容:
function myController($someDirectives, ...){
var ctrl = this;
// My code
}
The thing is when I JSHint my code, I get this warning message for all of my 'this' declared in controllers :
当我输入我的代码时,我在控制器中声明的所有" this "都会得到这个警告信息:
If a strict mode function is executed using function invocation, its 'this' value will be undefined.
如果使用函数调用执行一个严格的模式函数,那么它的“this”值将没有定义。
I must precise that in my .jshintrc file, I set "strict":false
. Does anyone know how to disable this message in particular?
我必须精确地指出,在我的.jshintrc文件中,我设置了“严格”:false。有人知道如何禁用这条消息吗?
Thanks in advance.
提前谢谢。
3 个解决方案
#1
15
set the configuration in .jshintrc
file
设置.jshintrc文件中的配置。
{
"validthis": true // Tolerate using this in a non-constructor
}
#2
3
You can always override jshint options in the code-block ie.
您可以在代码块ie中重写jshint选项。
/* jshint validthis: true */
#3
0
I'm having the same issue. I'm doing "indirect invocation" with the function in question, not "function invocation", and 'this' is referenced many times in the function body.
我也有同样的问题。我使用的是函数的间接调用,而不是“函数调用”,而“this”在函数体中多次被引用。
In my case, I was having so many of these "errors" that jsHint quit before scanning my whole script.
在我的例子中,我有太多这样的“错误”,以至于jsHint在扫描整个脚本之前就退出了。
To get around this I put this at the top of my script-file:
为了解决这个问题,我把它放在了我的脚本文件的顶部:
/*jshint maxerr: 10000 */
It did not suppress the errors, but at least it allowed me to scroll down to see jsHint's analysis of the entire script.
它没有抑制错误,但至少允许我向下滚动查看jsHint对整个脚本的分析。
#1
15
set the configuration in .jshintrc
file
设置.jshintrc文件中的配置。
{
"validthis": true // Tolerate using this in a non-constructor
}
#2
3
You can always override jshint options in the code-block ie.
您可以在代码块ie中重写jshint选项。
/* jshint validthis: true */
#3
0
I'm having the same issue. I'm doing "indirect invocation" with the function in question, not "function invocation", and 'this' is referenced many times in the function body.
我也有同样的问题。我使用的是函数的间接调用,而不是“函数调用”,而“this”在函数体中多次被引用。
In my case, I was having so many of these "errors" that jsHint quit before scanning my whole script.
在我的例子中,我有太多这样的“错误”,以至于jsHint在扫描整个脚本之前就退出了。
To get around this I put this at the top of my script-file:
为了解决这个问题,我把它放在了我的脚本文件的顶部:
/*jshint maxerr: 10000 */
It did not suppress the errors, but at least it allowed me to scroll down to see jsHint's analysis of the entire script.
它没有抑制错误,但至少允许我向下滚动查看jsHint对整个脚本的分析。