Javascript对象还可以,但是分别调用时属性值丢失

使用默认值创建一个对象:

var area = {
    id: id, // unique value: 0, 1, 2, 3 ...
    height: 0,
    width: 0,
    rtmx: 0
}

然后将属性值设置为新值。

稍后在代码中我们有:

console.log(area);
console.log('id: ' + area.id);
console.log('width: ' + area.width);
console.log('height: ' + area.height);
console.log('rtmx: ' + area.rtmx);

在控制台中:

Object {"id": 0,"height": 115,"width": 206,"rtmx": 30}
id: 0 // --> currect
width: 0 // --> incorrect, must be 206
height: 0 // --> incorrect, must be 115
rtmx: 0 // --> incorrect, must be 30

only id has correct value others return default values from creation time.

I tries area['rtmx'] and it was the same.

似乎该对象及其属性值存在,但是当分别调用属性值时,这些值会丢失或重置为默认值。

任何的想法?我很感激

评论