JSLint and commonJS "three function" failure

You must Login before you can answer or comment on any questions.

Hi Guys

I am running JSLint for validation, and I am finding that it is throwing an error on the third function in a commonJS module. For example:

function EmptyWindow() 
{
     ...
}
 
EmptyWindow.prototype.foo1 = function ()
{
    ....
}
 
 
EmptyWindow.prototype.foo2 = function ()
{
    ....
}
in this case, JSLint throws an "Unexpected 'EmptyWindow' error for foo2. If I change foo2 to be something else, say
Object.defineProperty( EmptyWindow, 'THIS_IS_A_VALUE',  {value:0, enumerable: true} );
then I get the error "Unexpected 'Object'. This is consistent over my entire code base.

I am using Titanium Studio, build: 2.1.2.201208301612

— asked 8 months ago by Richard George
2 Comments
  • Are you using the built in JSLint for validation, and if so, if you copy and paste your code into jslint.com does it validate??

    — commented 8 months ago by Anthony Decena

  • fails in jslint.com with the code above (cutting out the ellipse in each function of course)

    — commented 8 months ago by Richard George

2 Answers

Accepted Answer

Ok, so, yea man, you're not closing your variable functions:

function EmptyWindow() {}
 
EmptyWindow.prototype.foo1 = function () {
};
 
EmptyWindow.prototype.foo2 = function () {
};

— answered 8 months ago by Anthony Decena
answer permalink
2 Comments
  • And by closing, I just mean that you need a ;

    — commented 8 months ago by Anthony Decena

  • Ah, I don't need one after the "constructor". but I need them after the "methods" - wonderful, thanks :)

    — commented 8 months ago by Richard George

I encourage you to use K&R style indentation and line breaking with your JavaScript code. See Titanium Coding styles and conventions or Google's coding conventions pages for more info. Also keep in mind that statements should end with a semicolon. Failure to do so can result in "hard to debug" problems. See Google's page on semi-colons

// this is an assignment statement:
EmptyWindow.prototype.foo1 = function ()
{
    ....
} // and should end with a semicolon
 
// better to be written as:
EmptyWindow.prototype.foo1 = function () {
    ....
};

— answered 8 months ago by Tim Poulsen
answer permalink
1 Comment
  • Thank you for your concern, but K&R notation is the devil's spawn as far as readability goes. After over 30 years of writing C and related languages, I think I will stick to the format that allows for easy block matching and simple debugging.

    — commented 8 months ago by Richard George

Your Answer

Think you can help? Login to answer this question!