View Full Version : Object var still lingering EVEN after I clear the object with a "clone"..weird???

06-24-2004, 08:27 AM
Sorry for my constant questions..but..

Okay, I was able to "clone" the multi-dimensional array that I assigned to an Object Var....

when I 'alert" it....it shows fine...unmanipulated...good!

BUT...when I try to overrid the "previous object var reference"...it won't go away....its almost as if I am creating or there are two instances of the SAME OBJECT var, is this possible?

Can multiple object references exists within different functions?

Cause in my resetCart() function....
I kill the object..

var myObject = null;

then I reinstate it and funnel in the "clone" reference so that I assign a fresh copy of the multidimensional array ot the object var...

var myObject = new CartConent('','','',cloneCopy);

I then call to a rewriteDrops() function...

The thing is....in this rewriteDrops function....I do this...

for(i=0;i<myObject.cartData.length;i++) etc.....

its reference the "old" myObject.cartData object var....not the NEW assigned clone copy...and when I alert the clone...its fine and pristine...and unchanged...great....but it won't override what I need it to...

so I am thinking.....do I have mutliple local myObject.cartData 's running around???

06-24-2004, 10:43 AM
Can you post a simple demo page like below so that we can debug it easier?


function MyObject(arr){
this.arr = arr;

var obj;
var clone = [1,2,3];

function initObject(){
obj = new MyObject([1,2,3]);
alert("original: "+obj.arr);

function changeObject(){
obj.arr = [4,5,6];
alert("modified: "+obj.arr);

function resetObject(){
obj = null;
obj = new MyObject(clone);
alert("orig using clone: "+obj.arr);
<body onload="initObject()">
<input type="button" value="Change Object" onclick="changeObject()" />
<input type="button" value="Reset Object" onclick="resetObject()" />

Does that demo page exactly illustrate your problem?
That script outputs the expected result.

06-25-2004, 01:14 AM
what a friggin bonehead I am...I was setting a variable within the function with a VAR, thus it was a local copy and wasn't overriding the global that I set WITH VAR....geesh..
thanks for your time though...It was your code that made me realize my mistake!!
appreciate it.