If newcap
is enabled, JSHint expects functions starting with a capital letter to be constructors and therefore to be called with the new
keyword.
Solution: Either disable this option or rename your functions.
From the documentation:
This option requires you to capitalize names of constructor functions. Capitalizing functions that are intended to be used with
new
operator is just a convention that helps programmers to visually distinguish constructor functions from other types of functions to help spot mistakes when usingthis
.Not doing so won’t break your code in any browsers or environments but it will be a bit harder to figure out—by reading the code—if the function was supposed to be used with or without
new
. And this is important because when the function that was intended to be used withnew
is used without it,this
will point to the global object instead of a new object.function MyConstructor() { console.log(this); } new MyConstructor(); // -> [MyConstructor] MyConstructor(); // -> [DOMWindow]
For a more in-depth understanding on how this
works, read Understanding JavaScript Function Invocation and “this” by Yehuda Katz.