2
var rooms = {
bedroom: {
    info: "A dusty bed lies sideways in the midle of the room";

    north: function (  ) {
        //this function returns an error
    }
}
};

I cant work out why this returns an unexpected identifier

-- edit thanks another question

in javascript the good parts he has

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

is this different to what I am doing?

2
  • 1
    @fxmile - Looks like a mistake in the book. Is it on page 28 (or close by)? Something similar is listed in the errata for the book for that page. Commented Dec 8, 2010 at 21:35
  • ; instead of a ,. That is all. Commented Dec 26, 2024 at 10:16

3 Answers 3

4

One should use a , inside of object literals when defining keys and values to separate them, not ;.

var o = { name: 'john', age: 13 }
Sign up to request clarification or add additional context in comments.

Comments

2
the room";

There should be ,, not ;.

Comments

2

To answer your second question, it looks there is a typo in the book.

The incorrect example is:

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

The correct example is:

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

Note the comma on the line value: 0,.

As others have mentioned, the comma should be used (instead of the semicolon) for object literals.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.