firefox: 3.5.3, firebug: 1.4.2

I was working out some test code to demonstrate javascript behavior
when passing objects to functions, using console.log to report state.
I noticed something unexpected. When i modify the contents of an
array, all calls to console.log containing that array report the final
state of the array, not the state at the time the log request is made.
Sample code, run from within the console window:

var test = function (arr, val) {
    console.group("test func");

    var ia = arr;

    console.log( "ia = ", ia);

    if (ia.length) {
        ia[0] = "hola muchacha";
    }

    val = "new string";

    console.log( "ia = ", ia );
    console.log( "val = ", val );

    console.groupEnd();
};

var x = [1, 2, 3];
var y = 5;

console.log( "y = ", y, ", x = ", x );
test(x, y);

console.log( "y = ", y, ", x = ", x );

All outputs for the array in the console window read: ["hola
muchacha", 2, 3]

Seems like a bug. Alerts placed throughout the code display the
expected results.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Firebug" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/firebug?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to