Re: [whatwg] Proposal: Adding methods like getElementById and getElementsByTagName to DocumentFragments

On Sun, Jul 28, 2013 at 11:10 AM, Boris Zbarsky <bzbarsky@mit.edu> wrote:

> On 7/27/13 10:58 AM, Ojan Vafai wrote:
>
>> var iterator = document.querySelectorAll('**div').iterator(); <--- does
>> some magic to not precompute the whole list
>>
>
> Well, so... not precompute but make it some sort of live, or not
> precompute but represent a frozen set of nodes?
>
> What should happen with this situation:
>
>   var list = document.querySelectorAll('**div');
>   var iterator = list.iterator();
>
> Should the list of nodes be precomputed in this case?
>
> Basically, the magic sounds like it's ... very magical.  Magical enough
> that authors would have a tough time with this setup, even ignoring
> implementation concerns.


I was just picturing lazy computing the list. You don't need to compute the
list until you query the length or index into the NodeList, at which point,
if it's a static NodeList, you compute the whole thing in one go. If all
you ever do is grab the iterator, then no need to compute the list. So, the
example you give above would not precompute.

Now that I put it in writing, the obvious problem with this is that it's a
change in semantics. If you querySelectorAll and then modify the DOM before
reading the length or an index, then you get a different list. :(

Received on Sunday, 28 July 2013 21:00:14 UTC