Fork me on GitHub

JSLint Error Explanations

JSLint will hurt your feelings. It's time to make them better!


A constructor name '{a}' should start with an uppercase letter

When do I get this error?

JSLint will throw the "A constructor name '{a}' should start with an uppercase letter" error when it encounters a function whose identifier begins with a lowercase letter and is later referenced as the operand to the new operator. In the following example we declare a "class" myClass and then attempt to instantiate it:

Why do I get this error?

This error is raised to highlight a lack of convention. It is common practice for constructor function identifiers to begin with an uppercase letter. JSLint simply enforces this convention. Here's the above snippet rewritten to pass JSLint. Notice that the only difference is the uppercase "M":

It is worth bearing in mind that this is only a convention and is not required by the language in any way. You can safely ignore this error if you prefer to name your constructor functions differently. By setting the newcap option, you can tell JSLint to allow lowercase constructors.


comments powered by Disqus