admin管理员组文章数量:1023773
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.
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.
本文标签: simple javascriptfunctions in objectsStack Overflow
版权声明:本文标题:simple javascript, functions in objects - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745574396a2156929.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论