Don P: Race Condition?

Beitrag lesen

Hallo,

Das Array ist kein Array, sondern eine NodeList.

Stimmt ja, das vergesse ich immer wieder. In SELFHTML wird es leider immer als Array bezeichnet.

NodeList and NamedNodeMap objects in the DOM are live; that is, changes to the underlying document structure are reflected in all relevant NodeList and NamedNodeMap objects. For example, if a DOM user gets a NodeList object containing the children of an Element, then subsequently adds more children to that element (or removes children, or modifies them), those changes are automatically reflected in the NodeList, without further action on the user's part.”

Dann ist es klar. Ich habe mir eine Helferfunktion arrayOf() gebastelt, die eine solche Collection bzw. Nodelist zu einem echten Array macht und benutze sie auch meistens, weil dann gleich die nützlichen anderen Array-Funktionen wie filter, map, forEach usw. zur Verfügung stehen. Damit wäre dann auch das live-Problem gelöst, falls zum Problem werden sollte wie hier.

Gruß, Don P