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?
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?
Share Improve this question edited Dec 8, 2010 at 21:19 fxmle asked Dec 8, 2010 at 21:06 fxmlefxmle 1292 silver badges8 bronze badges 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. – user113716 Commented Dec 8, 2010 at 21:35
-
;
instead of a,
. That is all. – dumbass Commented Dec 26, 2024 at 10:16
3 Answers
Reset to default 4One should use a ,
inside of object literals when defining keys and values to separate them, not ;
.
var o = { name: 'john', age: 13 }
the room";
There should be ,
, not ;
.
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 ma on the line value: 0,
.
As others have mentioned, the ma should be used (instead of the semicolon) for object literals.