W3C home > Mailing lists > Public > whatwg@whatwg.org > April 2010

[whatwg] Adding ECMAScript 5 array extras to HTMLCollection

From: Erik Arvidsson <arv@chromium.org>
Date: Mon, 26 Apr 2010 09:43:40 -0700
Message-ID: <r2z34df39071004260943ydc4e521fu1ae31de63aa8ecc7@mail.gmail.com>
>> for (var i = 0, length = collection.length; i < length; i++)
>> // instead of:
>> for (var i = 0; i < collection.length; i++)
>>
>
> Actually, the former is a problem when the nodelist is modified in the
> loop; it may result in collection[i] being undefined.

Even when checking the length in every iteration you can run into
problems. If you remove something earlier in the collection you will
*miss* one item unless you fix the loop iterator.

We should not let these edge cases get in the way of making the DOM
collections feel less foreign to JavaScript.

--
erik
Received on Monday, 26 April 2010 09:43:40 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:22 UTC