JR
12/31/2015 11:24:00 PM
On 12/31/2015 04:41 PM, Aleksandro wrote:
> On 31/12/15 15:19, Evertjan. wrote:
>> Aleksandro <aleksandro@gmx.com> wrote on 31 Dec 2015 in
>> comp.lang.javascript:
>>
>>> On 31/12/15 11:15, JJ wrote:
>>>> On Thu, 31 Dec 2015 11:11:01 +0100, Evertjan. wrote:
>>>>>
>>>>> Would the "var m" assignment not prevent it
>>>>> from being a real orphan [in the sense of gabage-collectable]?
>>>>>
>>>>> ... as it can be reassigned anywhere in the DOM-tree later?
>>>>
>>>> Yes to both.
>>>>
>>>> It's like assigning a variable to the return value of removeChild() then
>>>> re-insert the node into the document later using appendChild() or
>>>> insertBefore(). Without saving a reference to the removed node, the node
>>>> would be a garbage.
>>>
>>> I think would apply the same rules as to any Javascript object.
>>
>> Is the Javascript-object garbage-collection the same as the DOM-tree-element
>> one?
>
> DOM elements are normal Javascript objects, or should be. Someone
> confirm please.
>
DOM objects are host objects (called exotic objects in ES6), not
ECMAScript's ordinary or standard built-in objects. The W3C defined the
DOM as a set of objects and interfaces for accessing and manipulating
document objects in a language-independent manner. The DOM presents
documents as a hierarchy of Node objects that also implement other, more
specialized interfaces.
If I write the following lines in my Chrome 47 (Linux Mint) console, I
will find the "HTMLParagraphElement" object.
var el = document.createElement('p');
console.log(el.constructor.prototype); // logs HTMLParagraphElement
And if I follow the prototype chain, I will find other object names that
correspond to DOM Level 4 interfaces:
HTMLParagraphElement
HTMLElement
Element
Node
EventTarget
Object
BTW, Happy New Year!
--
Joao Rodrigues