Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #16194

Re: Who's eaten my apple and why?

From Christoph Becker <cmbecker69@gmx.de>
Newsgroups comp.lang.javascript
Subject Re: Who's eaten my apple and why?
Date 2012-09-27 19:14 +0200
Organization Aioe.org NNTP Server
Message-ID <k421h5$7ka$1@speranza.aioe.org> (permalink)
References (2 earlier) <f097689vq8t2i4d344qhsse20dg9jephgj@4ax.com> <k40ct8$fmi$1@news.albasani.net> <kde7681jjln1ffu43grf11thd274pqkokf@4ax.com> <k41bjn$bdg$1@speranza.aioe.org> <pmv868t6raj29735oalaj0imefgpsj8uh1@4ax.com>

Show all headers | View raw


Gene Wirchenko wrote:
> On Thu, 27 Sep 2012 13:00:11 +0200, Christoph Becker
> <cmbecker69@gmx.de> wrote:
> 
>> Gene Wirchenko wrote:
>>>      I know he has it right.  I have run both sets of code.  The
>>> question is why is it that way?  He posted a reference that he claimed
>>> explains it, but it does not do so.
>>
>> Stefan has already explained, that the add() method of HTMLSelectElement
>> behaves similar to the appendChild() method of Node.  This is clearly
>> stated in the specs:
> 
>      It may be stated, but clearly?  Ha!
> 
>      Take a look at that again, and try telling me that it is clearly
> written and that someone new to using the DOM would understand the
> implications.

IMHO someone new to the DOM might better be served by a more gentle
introduction, e.g. the one available on MDN (I just wasn't able to find
the relevant information there).
> 
>> <http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-14493106>:
>>
>> | This method is the equivalent of the appendChild method of the Node
>> | interface if the before parameter is null.
>>
>> <http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-184E7107>
>>
>> | If the newChild is already in the tree, it is first removed.
> 
>      What on earth does this mean?  What gets stored in the tree when
> the method is called?
> 
>      An object reference?  Then, why does nulling the object not
> change the display?

Yes, indeed the reference to the object is stored.  But when you set the
variable containing the object reference to null later, the stored
object reference isn't affected (IIRC Stefan had already explained
that).  This has nothing to do with the DOM, but with the semantics of
ECMAScript.

IOW: you can't null any object.  You only can set a variable which
contains a reference to an object to null.  This doesn't affect the
object itself, only the variable changes.  If all references to an
existing object are gone, the object might be garbage collected (but
that is semantically irrelevant).

An example might clarify things:

var o1 = o2 = {a:1, b:2};
o2 = null;
console.log(o1);

Contrast this with:

var o1 = o2 = {a:1, b:2};
o2.a = 3;
console.log(o1);

HTH

>      The object's values?  Then, why wouldn't using the same object
> work a subsequent time?
> 
>> I should have added this information in the first place.
> 
> Sincerely,
> 
> Gene Wirchenko
> 

-- 
Christoph M. Becker

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Who's eaten my apple and why? justaguy <lichunshen84@gmail.com> - 2012-09-26 14:43 -0700
  Re: Who's eaten my apple and why? Christoph Becker <cmbecker69@gmx.de> - 2012-09-27 01:35 +0200
    Re: Who's eaten my apple and why? justaguy <lichunshen84@gmail.com> - 2012-09-26 17:46 -0700
      Re: Who's eaten my apple and why? Stefan Weiss <krewecherl@gmail.com> - 2012-09-27 03:51 +0200
        Re: Who's eaten my apple and why? justaguy <lichunshen84@gmail.com> - 2012-09-26 19:44 -0700
          Re: Who's eaten my apple and why? Stefan Weiss <krewecherl@gmail.com> - 2012-09-27 22:06 +0200
    Re: Who's eaten my apple and why? Gene Wirchenko <genew@ocis.net> - 2012-09-26 17:59 -0700
      Re: Who's eaten my apple and why? Stefan Weiss <krewecherl@gmail.com> - 2012-09-27 04:16 +0200
        Re: Who's eaten my apple and why? Gene Wirchenko <genew@ocis.net> - 2012-09-26 19:38 -0700
          Re: Who's eaten my apple and why? Stefan Weiss <krewecherl@gmail.com> - 2012-09-27 05:44 +0200
            Re: Who's eaten my apple and why? Gene Wirchenko <genew@ocis.net> - 2012-09-27 09:28 -0700
              Re: Who's eaten my apple and why? Tim Streater <timstreater@greenbee.net> - 2012-09-27 17:40 +0100
                Re: Who's eaten my apple and why? Gene Wirchenko <genew@ocis.net> - 2012-09-27 16:24 -0700
              Re: Who's eaten my apple and why? Dr J R Stockton <reply1239@merlyn.demon.co.uk.invalid> - 2012-09-29 20:47 +0100
          Re: Who's eaten my apple and why? Christoph Becker <cmbecker69@gmx.de> - 2012-09-27 13:00 +0200
            Re: Who's eaten my apple and why? Gene Wirchenko <genew@ocis.net> - 2012-09-27 09:34 -0700
              Re: Who's eaten my apple and why? Christoph Becker <cmbecker69@gmx.de> - 2012-09-27 19:14 +0200
                Re: Who's eaten my apple and why? Stefan Weiss <krewecherl@gmail.com> - 2012-09-27 21:40 +0200
                Re: Who's eaten my apple and why? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-28 15:39 +0200
                Re: Who's eaten my apple and why? Gene Wirchenko <genew@ocis.net> - 2012-09-27 16:25 -0700
      Re: Who's eaten my apple and why? Tim Streater <timstreater@greenbee.net> - 2012-09-27 08:52 +0100
  Re: Who's eaten my apple and why? Gene Wirchenko <genew@ocis.net> - 2012-09-26 17:50 -0700

csiph-web