Click to See Complete Forum and Search --> : reference to an object not persistent


molvisions
12-29-2005, 11:37 AM
hi,

I am trying to create an object and save a ref to it in another object's array:

function mainF(data) {
var H = new Hub(data);
subF(data);
return H;
}

function subF(data) {
// create the object
IB = new InfoBlock(data);
// save a ref to IB in a linked array set of the H object.
// id goes into one array, IB goes into the same position in another.
H.addInfoBlock(id, IB);
}

if I subsequently try to access the IB object by accessing the array in H, it returns undefined. if I try to access id from its array in H, though, it returns the correct value.

is my object is getting punked, or just the reference to it?

thanks!

tim

A1ien51
12-29-2005, 11:50 AM
if you structure your code like


function mainF(data) {

function subF(data) {
// create the object
IB = new InfoBlock(data);
// save a ref to IB in a linked array set of the H object.
// id goes into one array, IB goes into the same position in another.
H.addInfoBlock(id, IB);
}

var H = new Hub(data);
subF(data);
return H;

}


does that help?

Eric

molvisions
12-29-2005, 11:58 AM
hi Eric,

thanks for the prompt reply. unfortunately, nesting the functions did not change the result. I'm still getting undefined.

regards,

tim

A1ien51
12-29-2005, 12:16 PM
I really did not look at your code correctly.

Pass in H to the function like you do data.

Eric

molvisions
12-29-2005, 01:20 PM
hi Eric,

thanks for the help. I located my error, which is almost too dumb to post. I was incrementing the array incorrectly. the ref to the IB object was being stored after all - but I was trying to extract a non-existent array element. argh!

thanks,

tim