Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSLint says new keyword is missing [duplicate]

Let's say I have some 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);

Why should I rewrite as MyVar = new FunctionB(SomeParameter); Is there going to be any benefit?

like image 304
frenchie Avatar asked Dec 09 '22 02:12

frenchie


2 Answers

It is the convention that constructors (eg: Array, Object) are starting with a capital.

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

like image 111
Rob W Avatar answered Jan 04 '23 09:01

Rob W


JSLint thinks the function is a constructor since it's uppercase. Name your non-constructor functions with an initial lowercase letter and JSLint will stop complaining.

like image 27
Dagg Nabbit Avatar answered Jan 04 '23 09:01

Dagg Nabbit