Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cached object in console?

I'll start with the problem :

  1. I'm changing the content of an object literal. (changing the properties values)
  2. The Firebug console (at first clicks) shows the correct values.
  3. But after a while, it get stuck on a specific value and stop from changing.

(notice : the stringify representation of the object - Always shows the correct values)

And here are the Details:

  1. I select a street in the textbox (it should set the StreetText value in the object)

  2. I look at the console (wide line) and press the last line , looking at the street text.

At first it's OK. In the second try, after I choose another street, it stays on the old value.

However, when I press refresh (on the object), it shows me the correct street name.

What is going on here?

enter image description here

My object is a regular object literal :

  var obj =
            {
                getData: function ()
                {

                    obj.CountryId = $(".ddlCountry").val() || "";
                    obj.CountryText = $(".ddlCountry  :selected").text() || "";
                    obj.StateId = $(".ddlState:visible").val() || "";
                    obj.StateText = $(".ddlState:visible  :selected").text() || "";
                    obj.CityId = $(".hfDataIdCity").val() || "";
                    obj.CityText = $(".hfDataTextCity").val() || "";
                    obj.StreetId = $(".hfDataIdStreet").val() || "";
                    obj.StreetText = $(".hfDataTextStreet").val() || "";
                }
        }

and the display on the console is made by onclicking the button :

 obj.getData();
 console.log(obj);

Why I'm not seeing the correct values ? ( only after refresh....)

p.s. : ff: 14.0.1
fb:1.10.6

and the cache is turned off

enter image description here

like image 638
Royi Namir Avatar asked Feb 04 '13 14:02

Royi Namir


1 Answers

Use console.dir(obj) for objects not console.log(obj), you are getting a string of the object by doing that so updating it will still work in your code but not show in the console. Strings are immutable, so no property update wil show in your console. Tip: Use watch expressions in chrome debugger.

like image 180
Rick Hurst Avatar answered Sep 17 '22 14:09

Rick Hurst