How to disable warnings about 'this' and strict mode using JSHint?

女生的网名这么多〃 提交于 2019-12-10 12:39:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!