3 ms·
Iterating a NodeList isn't so bad: Array.prototype.forEach.call( document.querySelectorAll('a'), function(el){ console.log(el); }); But, I agree w
by jackmoore 14y ago
Iterating a NodeList isn't so bad:
Array.prototype.forEach.call(
document.querySelectorAll('a'), function(el){
console.log(el);
});
But, I agree with the point. If the NodeList isn't live, like it is for the other DOM querying methods, then what is the point in returning a NodeList instead of an array?
- masklinn 14y agoThe DOM WebIDL does not know what an array is. Though an IDL extension/annotation added some time ago allows inheriting IDL interfaces from core language objects or interfaces rather than the root object (http://dev.w3.org/2006/webapi/WebIDL/#ArrayClass http://dev.w3.org/2006/webapi/WebIDL/#ArrayClass), and DOM4 adds this annotation to NodeList http://dom.spec.whatwg.org/#interface-nodelist http://dom.spec.whatwg.org/#interface-nodelist
- ahoge 14y agoFWIW, they fixed that crap in Dart. All those array-like things are indeed just regular arrays.