node object gets clobbered after clone

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard Trahan

    #1

    node object gets clobbered after clone

    I'm a js newbie, and I'm sure I'm missing something; please help me
    find it.

    Consider these fragments:

    function reconstruct_sel ect_node(select node,nodearray) {
    alert("120: "+typeof(select node));
    newselnode = selectnode.clon eNode(false); // shallow clone
    ... (operations only on newselnode)
    alert("139: "+typeof(select node));
    return newselnode;
    }
    ....
    ar = new Object();
    ar.selectgraphs node = (some node object)
    ....
    alert("405: " + typeof(ar.selec tgraphsnode));
    newselnode = reconstruct_sel ect_node(ar.sel ectgraphsnode,s na);
    alert("407: " + typeof(ar.selec tgraphsnode));

    The alerts at lines 120, 139, and 405 report type "Object", but
    the alert at line 407 is "undefined" .

    I have an easy workaround for this, but I'd like to understand
    what is happening.

    Any help, please. Thanks.

  • Lasse Reichstein Nielsen

    #2
    Re: node object gets clobbered after clone

    Richard Trahan <rtrahan@optonl ine.net> writes:
    [color=blue]
    > function reconstruct_sel ect_node(select node,nodearray) {
    > alert("120: "+typeof(select node));
    > newselnode = selectnode.clon eNode(false); // shallow clone[/color]

    Notice that "newselnode " is not declared as a local variable, so it
    is created as a global one. That is probably not your intent (no
    need to return it in that case), so you might vant to add "var" in
    front of "newselnode " here.
    [color=blue]
    > ... (operations only on newselnode)[/color]

    They don't affect "ar"?
    [color=blue]
    > alert("139: "+typeof(select node));
    > return newselnode;
    > }
    > ...
    > ar = new Object();
    > ar.selectgraphs node = (some node object)
    > ...
    > alert("405: " + typeof(ar.selec tgraphsnode));
    > newselnode = reconstruct_sel ect_node(ar.sel ectgraphsnode,s na);[/color]

    What is "sna"'s value?
    [color=blue]
    > alert("407: " + typeof(ar.selec tgraphsnode));
    >
    > The alerts at lines 120, 139, and 405 report type "Object", but
    > the alert at line 407 is "undefined" .[/color]

    Try alerting the type of "ar.selectgraph snode" at line 102 and 139
    as well.
    [color=blue]
    > I have an easy workaround for this, but I'd like to understand
    > what is happening.[/color]

    So would I, but you have to supply more code. Obviously, something
    goes wrong somewhere, and I'll bet it's in the code we cannot see.
    If you have a page that exhibits the problem, give us a link.

    Good luck.
    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    Working...