问题
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 :
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 :
If a strict mode function is executed using function invocation, its 'this' value will be undefined.
I must precise that in my .jshintrc file, I set "strict":false
.
Does anyone know how to disable this message in particular?
Thanks in advance.
回答1:
set the configuration in .jshintrc
file
{
"validthis": true // Tolerate using this in a non-constructor
}
回答2:
You can always override jshint options in the code-block ie.
/* jshint validthis: true */
回答3:
I had the same issue, with a very similar environment angular 1.5.5
always getting the same lint warning:
If a strict mode function is executed using function invocation, its 'this' value will be undefined.
I've changed the name of my component's main function starting with upper-case and the warning disappeared
function MyController($someDirectives, ...){
回答4:
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.
In my case, I was having so many of these "errors" that jsHint quit before scanning my whole script.
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.
来源:https://stackoverflow.com/questions/42349051/how-to-disable-warnings-about-this-and-strict-mode-using-jshint