compat-table icon indicating copy to clipboard operation
compat-table copied to clipboard

For..of with HTMLCollection & NodeList

Open Zefling opened this issue 9 years ago • 7 comments

I think it would be nice to add these two tests.

HTMLCollection:

var result = 3;
var list = document.createElement("span");
for (var i= 0; i < result; i++) {
  list.appendChild(document.createElement("span"));
}
var count = 0;
for (var item of list.children) {
  count++;
}
return result === count;

NodeList:

var result = 3;
var list = document.createElement("span");
for (var i= 0; i < result; i++) {
  list.appendChild(document.createElement("span"));
}
var count = 0;
for (var item of list.childNodes) {
  count++;
}
return result === count;

Zefling avatar Sep 16 '15 23:09 Zefling

This is the ECMAScript compatibility table - HTMLCollection and NodeList aren't part of ECMAScript.

ljharb avatar Sep 17 '15 01:09 ljharb

Yep, although I've been meaning to add some of the browser-specific stuff as well coz I think it's super useful.

Perhaps in non-standard table or someplace else?

Some of the oldie tests of this type:

http://kangax.github.io/jstests/symbol-tostringtag/

http://kangax.github.io/jstests/es5-api-host-objects/

kangax avatar Sep 17 '15 01:09 kangax

I think a browser-specific tab would be good, if it's another table - since many of the engines tested on the other pages include non-browsers.

ljharb avatar Sep 17 '15 01:09 ljharb

Ok, HTMLCollection and NodeList are non-standard specifics of Collection and List. Add a tab for browser test is a good proposal for me.

Zefling avatar Sep 17 '15 08:09 Zefling

@heycam anything else we can add?

kangax avatar Sep 17 '15 16:09 kangax

You could add support for Elements which should be a subclass of Array, but that isn't finalised yet, I think.

webbedspace avatar Sep 18 '15 04:09 webbedspace

Unlike NodeList, I can't find anything about iterability HTMLCollection in the specs.

zloirock avatar Feb 07 '16 14:02 zloirock