Reputation: 163
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.
Upvotes: 16
Views: 7058
Reputation: 31
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, ...){
Upvotes: 2
Reputation: 15770
You can always override jshint options in the code-block ie.
/* jshint validthis: true */
Upvotes: 9
Reputation: 11409
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.
Upvotes: 1
Reputation: 6796
set the configuration in .jshintrc
file
{
"validthis": true // Tolerate using this in a non-constructor
}
Upvotes: 21