W3C home > Mailing lists > Public > public-html@w3.org > April 2014

Re: Elements array and query/queryAll methods

From: Rick Waldron <waldron.rick@gmail.com>
Date: Tue, 8 Apr 2014 14:32:23 -0400
Message-ID: <CAHfnhfr3s3bSQ2KVW9ZGA0q96TT4-s+thR6wTx8_TYUKU-ZRNQ@mail.gmail.com>
To: Dean Edwards <dean.edwards@gmail.com>
Cc: Anne van Kesteren <annevk@annevk.nl>, Travis Leithead <travis.leithead@microsoft.com>, Eric Devine <devineej@gmail.com>, "public-html@w3.org" <public-html@w3.org>, "www-dom@w3.org" <www-dom@w3.org>
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:11 UTC

This archive was generated by hypermail 2.3.1 : Thursday, 29 October 2015 10:16:38 UTC