Simple javascript, functions in objects

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

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

I cannot understand why this returns an unexpected identifier

- change thanks one more question

in javascript the good parts that it has

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

different from what i do?

+3
source share
3 answers

To define keys and values, you must use ,inside object literals, not ;.

var o = { name: 'john', age: 13 }
+5
source
the room";

It should be ,, not ;.

+2
source

, , .

:

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

:

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

value: 0,.

, ( ) .

+2

Source: https://habr.com/ru/post/1779270/


All Articles