Jason Doucette
Jason Doucette

Reputation: 307

Aptana complaining about JavaScript semicolons

Why does Aptana with either validator (Mozilla or JSlint) complain about this code:

var collectionOfValues = {
    key0 : value0;
    key1 : value1;
    key2 : value2;
};

It works fine with , but not with ;.

Even code from The Good Parts won't validate:

var myObject = {
    value: 0;
    increment: function (inc) {
        this.value += typeof inc === 'number' ? inc : 1;
    }
};

Upvotes: 2

Views: 386

Answers (3)

Max
Max

Reputation: 33

I know that this is a late answer, but The Good Parts is right actually. (The questioner probably knows this, but for anyone else reading this....); my copy is dated 2008 and this post is 2011. It is printed with a comma.

It's the next bit that baffles me... ;-)

Upvotes: 0

Joseph Marikle
Joseph Marikle

Reputation: 78580

because proper syntax would be

var collectionOfValues = {
    key0 : value0,
    key1 : value1,
    key2 : value2,
};

for a js object

Upvotes: 2

Pointy
Pointy

Reputation: 413996

It's complaining because that's a syntax error. In an object literal, you separate terms with commas, not semicolons.

var collectionOfValues = {
    key0 : value0,
    key1 : value1,
    key2 : value2
};

Both your examples would be rejected by every JavaScript implementation I know of.

var myObject = {
    value: 0,
    increment: function (inc) {
        this.value += typeof inc === 'number' ? inc : 1;
    }
};

This has been the case essentially since the Big Bang.

Upvotes: 8

Related Questions