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

[Bug 5851] Consider adding .toArray() on NodeList and HTMLCollection

From: <bugzilla@wiggum.w3.org>
Date: Fri, 11 Jul 2008 08:59:22 +0000
To: public-html-bugzilla@w3.org
Message-Id: <E1KHETK-0000Ex-2o@wiggum.w3.org>


--- Comment #5 from Lachlan Hunt <lachlan.hunt@lachy.id.au>  2008-07-11 08:59:21 ---
(In reply to comment #4)
> If efficiency is key than it makes more sense to add an extra argument to the
> method that says it's to return a static array iso a live nodelist. That way
> you're even allowed to do this:
> var foo = document.getElementsByTagName('div', RETURN_STATIC_ARRAY).reverse();

That's not backwards compatible and makes it more difficult for JS libraries to
provide the functionality in legacy browsers.  It would require the script to
do replace the method itself, check for the extra paramter and return an array.

document._getElementsByTagName = document.getElementsByTagName;
document.getElementsByTagName = function(tagName, static) {
  var list = document._getElementsByTagName(tagName);
  if (static) {
    var array = [].slice.call(foo, 0);
    return array;
  return list;

That would also have to be done separately for every other existing and future
method that returns a NodeList on both document and the element nodes.  Adding
a single method that deals with all node lists regardless of where they come
from is much easier to implement and use.

Configure bugmail: http://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
Received on Friday, 11 July 2008 08:59:56 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 16:30:34 UTC