W3C home > Mailing lists > Public > public-html@w3.org > July 2009

Re: Clarification on "live NodeList"

From: Andrew Fedoniouk <news@terrainformatica.com>
Date: Fri, 10 Jul 2009 16:24:06 -0700
Message-ID: <4A57CD96.4030806@terrainformatica.com>
To: Boris Zbarsky <bzbarsky@MIT.EDU>
CC: Philip Taylor <pjt47@cam.ac.uk>, HTML WG <public-html@w3.org>
Boris Zbarsky wrote:
> Andrew Fedoniouk wrote:
>>>         if(nodeType != null && nodeType != 'undefined') {
>>>             var remNodes = atNode.getElementsByTagName(nodeType);
>>>         }
>>>         else {
>>>             var remNodes = atNode.childNodes;
>>>         }
>>>         var nodeLim = remNodes.length;
>>>         for(var x = 0; x<nodeLim; x++) {
>>>             atNode.removeChild(remNodes[0]);
>>>         }
>>>
>> I am not sure this piece will run at all.
>> remNodes will not be seen outside blocks where they declared: { var 
>> remNodes = whatever }
>
> I suggest reading up on variable scoping in ECMAScript.  var has 
> function scope.  In fact, the following is a perfectly valid 
> ECMAScript construct:
>
>   function foo() {
>     alert(x);
>     var x;
>   }
>
> and will alert undefined.  Removing the var declaration will throw an 
> exception due to x not being defined.
Oh! And also this....

It means that call/stack frame here

function foo()
{
   if(..) {
     var one = ...;
  } else {
     var two = ...;
  }
}
needs to be as twice bigger than it is needed. But who cares of course 
these days....

Thanks for the reminder, Boris.

>
>> But this counts as a proof that it might be some code in the wild 
>> that rely on this.
> Sure is (esp. note that this is a library used by all sorts of sites).
I can imagine. That's just highlights responsibility of public standards 
developers.
Forests on this planet will go away slightly sooner because of tons of 
"small" things like that live NodeList.
>
> -Boris
>
>
--
Andrew Fedoniouk.

http://terrainformatica.com
Received on Friday, 10 July 2009 23:24:52 UTC

This archive was generated by hypermail 2.3.1 : Thursday, 29 October 2015 10:15:48 UTC