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

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





--- Comment #6 from crisp <crisp@tweakers.net>  2008-07-11 09:49:24 ---
The same goes for toArray(), you do need to implement switching logic anyway
because this simply will not work either:

var foo = document.getElementsByTagName('div').toArray();

and afaik there is no way in legacy browsers to make this work since one
browser doesn't support expando's on interface objects *at all* and I can't
even make this work in at least Firefox:

if (!HTMLCollection.prototype.toArray)
{
 HTMLCollection.prototype.toArray = function()
 {
  return [].slice.call(this, 0);
 }
}

(assuming this is the right object, I tried NodeList too for good measure)

the only option is to prototype toArray on Object, and we all know that that's
not good practice.

Imo a generic toArray method for live nodelists is just syntax sugering and
doesn't really solve the problem of the concept of live nodelists being
unintuitive; you will need to know about the fact anyhow to know that you can
use toArray() (in some unforeseeable future).

And like I said: if performance is key a native toArray method is far less
performant than an extra argument. And how much will it's performance gain be
over [].slice.call? Will that be worth the trouble?


-- 
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 09:50:01 UTC