Buffering references

0 views
Skip to first unread message

malydog

unread,
Feb 16, 2009, 7:21:06 PM2/16/09
to Firebug
Firebug's buffering causes an "issue" in the logged output.

The code below demonstrates:

var d = new Date();
for(var i=0; i< 1000; i++)
{
if(i == 200)
{
console.log(d);
}
else if(i == 201)
{
d.setFullYear(2010);
}
else
{
console.log(i); //comment this line out to see the output
without buffering
}
}


Firebug clearly buffers the logged parameters rather than a formatted
log message. In this case it bufferes the reference to the date
object 'd', by the time it gets to log 'd' other code has changed some
of the object properties and the changed values are logged.

I guess this could be classed intended behaviour or an issue.
Wondering what the view on this is?

John J Barton

unread,
Feb 16, 2009, 7:39:29 PM2/16/09
to Firebug
Firebug does not buffer the log output, but neither is the log output
a list of strings. If you send a pointer to the log, a pointer is
placed there. So in your example, 'd' is placed in the log. If you
change the value that 'd' points to, then later examine 'd', you will
get the new value.

If you want to log the value of 'd', then you want something like
console.log(d+"");

May be what one wants is a deep copy snap shot of 'd', where the
properties of 'd' are frozen at the values 'd' had at log time. But
this is very expensive and not what you want other times. Perhaps
there is simple way to create this that I don't know about.


jjb

Hernan Rodriguez Colmeiro

unread,
Feb 17, 2009, 6:44:39 AM2/17/09
to fir...@googlegroups.com
I think john what he's refering is just what he says. Take this two
code samples:

Listing 1:
var d = new Date();
var d = new Date();
for(var i = 0; i<40; i++){
if(i==29)
console.log(d);
else if(i==30)
d.setFullYear(2010);
else
console.log(i)
}

Listing 2:
var d = new Date();
for(var i = 0; i<40; i++){
if(i==30)
console.log(d);
else if(i==31)
d.setFullYear(2010);
else
console.log(i)
}

In the Listing1, the output of console.log(d) is:
Tue Feb 17 2009 09:37:28 GMT-0200 (ARST)

But in the Listing2 the output is:
Wed Feb 17 2010 09:35:05 GMT-0200 (ARST)

And you can see that the only difference between the two listings is
the step of the loop in which I change the year and do the log. I can
see that when i reach 29 the console stops for a split of second and
then continues till the end of the execution in bigger loops (500
loops is big enough).

Hernán
Reply all
Reply to author
Forward
0 new messages