W3C home > Mailing lists > Public > whatwg@whatwg.org > September 2012

Re: [whatwg] [canvas] Proposal for supportsContext

From: Tobie Langel <tobie.langel@gmail.com>
Date: Mon, 10 Sep 2012 21:28:50 +0200
Message-ID: <-6600886849904536048@unknownmsgid>
To: Dean Jackson <dino@apple.com>
Cc: "whatwg@lists.whatwg.org" <whatwg@lists.whatwg.org>
On Sep 10, 2012, at 8:14 PM, Dean Jackson <dino@apple.com> wrote:

> I propose adding a new method to HTMLCanvasElement:
>
> interface HTMLCanvasElement : HTMLElement {
>  boolean supportsContext(DOMString contextId, any... arguments);
> };
>
> supportsContext takes the same parameters as getContext, and simply returns
> true if the corresponding call to getContext would have returned a valid
> context, false otherwise.

What about enabling feature detection by providing a method per context?

interface HTMLCanvasElement : HTMLElement {
  object get2DContext();
  object getWebGLContext(any... args);
};

That way, developers can use idiomatic JS for feature testing like
pretty much everywhere else on the Web platform:

if (canvas.get2DContext) {
  // do stuff with 2D canvas
}

--tobie
Received on Monday, 10 September 2012 19:29:17 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:45 UTC