1

An object is created with default values:

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

then property values set to new values.

later in code we have this:

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

in console:

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.

It seems the very object and its property values exist, but when property values are called separately values are lost or get reset to defaults.

Any idea? I appreciate.

Reza Mortazavi
  • 329
  • 3
  • 14
  • Where are you setting the other property values. – Thalaivar May 11 '20 at 14:05
  • 2
    Yeah, this is definitely mysterious. Any chance you could get a [mcve] snippet in the question? I agree that the behavior you are seeing appears incorrect, but there is nothing apparent shown that would cause it. – Alexander Nied May 11 '20 at 14:06
  • Please do re-check on your console.log statements. – Thalaivar May 11 '20 at 14:08
  • pretty certainly a duplicate of https://stackoverflow.com/q/23667086/1048572 and/or https://stackoverflow.com/q/23392111/1048572 – Bergi May 11 '20 at 14:22
  • @Thalaivar this is not the quesion of 'where is set', it's already set and object is live. the `console.log` part is all together in sequential order. – Reza Mortazavi May 11 '20 at 15:47
  • @AlexanderNied This is part of a bigger component but these lines are inside one single function. I'll try to extract a usable sample ASAP. – Reza Mortazavi May 11 '20 at 15:49
  • @Thalaivar it's already the third day stuck here, so, lot's of re-checks. – Reza Mortazavi May 11 '20 at 15:51
  • @Bergi you are wrong, this has nothing with async Ajax methods and request response situations, and it's not browser's console bug, it's the same as in `alert()` – Reza Mortazavi May 11 '20 at 15:53
  • 2
    @RezaMortazavi No. `alert(area)` will not alert "*Object {"id": 0,"height": 115,"width": 206,"rtmx": 30}*". – Bergi May 11 '20 at 16:07
  • 1
    Could this object is getting processed to be given custom [getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) that return the unexpected result? Perhaps the Chrome devtools have some way of circumventing getters when displaying the whole object rather than each individual property. Another possibility is some invisible character issues or something similar. You might try to loop through the object using [`Object.keys`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys) to see if you get the same result... – Alexander Nied May 11 '20 at 17:54
  • @AlexanderNied I'm using FF dev tools. no custom getters, object's what it is. I already checked for invis chars, `Object.keys` returns keys but looping returns default values. At the time being I guess @bergi is somehow right and there is a ghost object with values which has been misleading me. Thanks to a workaround the issue is no longer urgent but I'll still eager to find the reason and I'll be back to this problem in a couple of days after finishing up this job. – Reza Mortazavi May 12 '20 at 06:28

0 Answers0