Re: Elements array and query/queryAll methods

On Tue, Apr 8, 2014 at 1:39 PM, Dean Edwards <dean.edwards@gmail.com> 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

Received on Tuesday, 8 April 2014 18:33:12 UTC