473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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_select_node(selectnode,nodearray) {
alert("120: "+typeof(selectnode));
newselnode = selectnode.cloneNode(false); // shallow clone
... (operations only on newselnode)
alert("139: "+typeof(selectnode));
return newselnode;
}
....
ar = new Object();
ar.selectgraphsnode = (some node object)
....
alert("405: " + typeof(ar.selectgraphsnode));
newselnode = reconstruct_select_node(ar.selectgraphsnode,sna);
alert("407: " + typeof(ar.selectgraphsnode));

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.

Jul 23 '05 #1
1 1267
Richard Trahan <rt*****@optonline.net> writes:
function reconstruct_select_node(selectnode,nodearray) {
alert("120: "+typeof(selectnode));
newselnode = selectnode.cloneNode(false); // shallow clone
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.
... (operations only on newselnode)
They don't affect "ar"?
alert("139: "+typeof(selectnode));
return newselnode;
}
...
ar = new Object();
ar.selectgraphsnode = (some node object)
...
alert("405: " + typeof(ar.selectgraphsnode));
newselnode = reconstruct_select_node(ar.selectgraphsnode,sna);
What is "sna"'s value?
alert("407: " + typeof(ar.selectgraphsnode));

The alerts at lines 120, 139, and 405 report type "Object", but
the alert at line 407 is "undefined".
Try alerting the type of "ar.selectgraphsnode" at line 102 and 139
as well.
I have an easy workaround for this, but I'd like to understand
what is happening.


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 - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ryan Mitchley | last post by:
Hi all I have code for an object factory, heavily based on an article by Jim Hyslop (although I've made minor modifications). The factory was working fine using g++, but since switching to the...
6
by: Derek Hart | last post by:
I bring in an xml file into vb.net by using xmlDoc.LoadXml(XMLString) - I run xpath statements against the xml file to grab data from it, so I use, as an example, //Vehicles/Vehicles/@make to get...
5
WebDunce
by: WebDunce | last post by:
Hi guys, I am trying to develop a simple xml editor. I have an object that has a TreeView. I use the TreeView to display the Xml node info. That's all fine, but i want the user to be able to move...
15
by: mark.norgate | last post by:
Hello I want to create a reference to an object, so that changes to the referenced object are reflected in the other object. Like this: object o = 123; object p = o; o = 456;
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.