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

http://www.w3.org/Bugs/Public/show_bug.cgi?id=5851





--- 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