Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    349
    Thanks
    2
    Thanked 0 Times in 0 Posts

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

    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???

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Can you post a simple demo page like below so that we can debug it easier?
    Code:
    <html>
    <head>
    <script>
    
    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);  
    }
    </script>
    </head>
    <body onload="initObject()">
    <form>
    <input type="button" value="Change Object" onclick="changeObject()" />
    <input type="button" value="Reset Object" onclick="resetObject()" />
    </form>
    </body>
    </html>
    Does that demo page exactly illustrate your problem?
    That script outputs the expected result.
    Last edited by glenngv; 06-24-2004 at 09:46 AM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    349
    Thanks
    2
    Thanked 0 Times in 0 Posts
    thanks,,,,
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •