Re: Elements array and query/queryAll methods
Rick Waldron <[email protected]>
| Newsgroups | gmane.comp.web.dom.general |
|---|---|
| Message-ID | <CAHfnhfr3s3bSQ2KVW9ZGA0q96TT4-s+thR6wTx8_TYUKU-ZRNQ@mail.gmail.com> |
On Tue, Apr 8, 2014 at 1:39 PM, Dean Edwards <[email protected]> wrote: > The question I have about this proposal is how do we handle people > adding non-elements to the array? > > var elems = document.queryAll("p"); > elems.push(null); > elems.queryAll("span"); > class Elements extends Array { ... push(...elems) { // not necessarily instanceof, but some kind of check that's similar: if (!elems.every(elem => elem instanceof Element)) { throw some exception } super(...elems); } ... } Rick