JSLint says no new keyword

Let's say I have JavaScript that looks like this:

function A() { var MyVar, SomeParameter; // do work MyVar = FunctionB(SomeParameter); } 

JsLint says I'm Missing 'new'. at the line MyVar = FunctionB(SomeParameter); Missing 'new'. at the line MyVar = FunctionB(SomeParameter);

Why should I rewrite it as MyVar = new FunctionB(SomeParameter); Will there be any benefit?

+4
source share
2 answers

It is a convention that constructors (for example: Array , Object ) start with capital.

JSLint complains because it thinks you're trying to use the constructor without the new keyword. To fix the problem, start your function with a character other than uppercase.

+9
source

JSLint considers the function to be a constructor because it is uppercase. Call your unconstructor function the initial lowercase letter, and JSLint will stop complaining.

+5
source

Source: https://habr.com/ru/post/1400771/


All Articles