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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With