Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-21-2004, 08:04 PM   PM User | #1
deadseasquirrel
Regular Coder

 
Join Date: Feb 2004
Posts: 192
Thanks: 0
Thanked 0 Times in 0 Posts
deadseasquirrel is an unknown quantity at this point
is appendChild() appending a reference to an object or a copy

If I do appendChild(obj), is that a refernce to an object or a copy of that object?

If it was a reference, then if i did this in sequence:

parent.appendChild(obj);
obj = something_else;

Then in theory parent would have a child that is equal to "something_else" however if it was a copy, I could just reusing the obj object for something else just as.

obj = something_else_again;

and parent would still have a child that is equal to something_else.

Which one is it?
deadseasquirrel is offline   Reply With Quote
Old 05-21-2004, 08:19 PM   PM User | #2
sad69
Senior Coder

 
Join Date: Feb 2004
Posts: 1,206
Thanks: 0
Thanked 0 Times in 0 Posts
sad69 is an unknown quantity at this point
Reference -- but you're a bit off on your thinking..

obj is a reference to an object, a pointer if you will. parent.appendChild(obj) appends the object as a child of parent, the object obj referred/pointed to.

obj = something_else; doesn't delete object, but has obj reference a different object: something_else. The first object obj referred to, still has a reference: it's one of the childNodes of parent.

I know it's sort of confusing, but that's the way it works. An object doesn't disappear (get garbage collected) until it has lost all references to itself. In your example, there's still one reference to it.

If that doesn't make sense, post back and tell me what you do understand.. if I'm incorrect, please somebody correct me.

Sadiq.
sad69 is offline   Reply With Quote
Old 05-21-2004, 08:22 PM   PM User | #3
deadseasquirrel
Regular Coder

 
Join Date: Feb 2004
Posts: 192
Thanks: 0
Thanked 0 Times in 0 Posts
deadseasquirrel is an unknown quantity at this point
Thanks, I do understand, I've done a good deal of programming. But DOMs for whatever reason is really confusing me, maybe it is that one additional layer of referencing that I kind of see in DOM which is throwing me off. It's like when I think I've finally gotten to the object itself, I actually only got to the reference to an object.

So is it safe to say then that appendChild(obj) appends the object and not the reference. Because if it appends the reference, whenever that reference points to something different then the appended child will be something different.
deadseasquirrel is offline   Reply With Quote
Old 05-21-2004, 08:30 PM   PM User | #4
sad69
Senior Coder

 
Join Date: Feb 2004
Posts: 1,206
Thanks: 0
Thanked 0 Times in 0 Posts
sad69 is an unknown quantity at this point
Yes, it appends the object. See? You've already got it!

It is tricky though, I agree. Sometimes I don't know if I've got the right object or what's going on.. and when you got to change something, oh man!! But it keeps you sharp

Happy coding,
Sadiq.
sad69 is offline   Reply With Quote
Old 05-21-2004, 08:49 PM   PM User | #5
deadseasquirrel
Regular Coder

 
Join Date: Feb 2004
Posts: 192
Thanks: 0
Thanked 0 Times in 0 Posts
deadseasquirrel is an unknown quantity at this point
Sad69,
Maybe you have a good suggestion to test what you have a handle on. I am just using alert(), but in the old days, with java or C++, if I had a handle on the reference I would get back with system.out.println():

ajsoadkj232r4 or something like that

or "hello world" if it was the actual object.

But with alert() half the time I just get undefined. And I don't know what that really means. Is there a better way to check?
deadseasquirrel is offline   Reply With Quote
Old 05-21-2004, 09:07 PM   PM User | #6
sad69
Senior Coder

 
Join Date: Feb 2004
Posts: 1,206
Thanks: 0
Thanked 0 Times in 0 Posts
sad69 is an unknown quantity at this point
Not really.. if I get undefined, I just just go back up one level and see where I'm at. After a while of that if I'm still lost, I just step back and re-evaluate what I'm trying to do.

I use paper and pencil for lots of stuff. innerHTML is a good one to alert() when appropriate. When you were working with Java and C++, did you ever work with trees? Binary or n-ary or something? Because that's what DOM is. It's an n-ary tree or Nodes. Nodes can be Elements....

When working with Java, I'm sure you know about APIs. Here's a good one that I use for DOM (since DOM uses Javascript and APIs as a result..):
http://krook.org/jsdom/Node.html

Hope that helps,
Sadiq.
sad69 is offline   Reply With Quote
Old 05-21-2004, 09:09 PM   PM User | #7
deadseasquirrel
Regular Coder

 
Join Date: Feb 2004
Posts: 192
Thanks: 0
Thanked 0 Times in 0 Posts
deadseasquirrel is an unknown quantity at this point
Thanks, that does help. I was wondering why there wasn't a readily available javascript DOM API, even if it were specific to specific browsers, I would like to see something.
deadseasquirrel is offline   Reply With Quote
Old 05-22-2004, 02:27 AM   PM User | #8
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
Now I think you've confused things... the DOM is an API. The ECMAScript bindings are standardised, if you want to see the specification for them you can have a look at <http://www.w3.org/DOM/DOMTR>. Not all browsers behave according to the specification, however, and some browsers add proprietary extensions to it. A prime example of this is innerHTML, a proprietary extension added by iew that all browsers support for compatibility reasons, in difference to outerHTML.

As for browser implementation documentation, MSDN has a very complete and accurate one for iew (not so for iem). The Gecko DOM documentation is both old and incomplete, but it's still pretty good. Both of these are linked from my sig. (MSDN: DHTML and Moz: DOM, respectively)

Opera and Safari behaves pretty much according to the specification for what they support. Safari documentation is sparse, but Opera has a nice standards compliancy report.
__________________
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards
liorean is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:35 PM.


Advertisement
Log in to turn off these ads.