In JavaScript it is possible to define classes and instantiate objects, as in the following example:

//Define the class
function MyClass(){
    this.attribute1 = 0;
    this.attribute2 = 1;
    this.method1 = function() {
        alert("test");
    };
}

//Instantiate and use the class:
var myobj = new MyClass();
myobj.method1();

JSLint isn’t all about spotting potential problems; it’s also about getting developers to adopt a consistent style, which is the main thrust of this message. For reference, is only a warning, and can be turned off using the newcap option:

true: require caps on constructor
false: ignore this rule

For example:

/*jslint newcap:true */

For discussion on the use of objects in JavaScript, refer to JavaScript and Object Oriented Programming (OOP)

A Guide To JSLint Messages

This article is one of a series on the error and warning messages produced by JSLint.

, , ,
Trackback

only 1 comment untill now

  1. [...] in a block. (removed) A ‘<{a}>’ must be within ‘<{b}>’. A constructor name should start with an uppercase letter. A dot following a number can be confused with a decimal point. A leading decimal point can be [...]

Add your comment now