Re: [dom] Added an example showing feature detection with supports() (#144)

> @@ -8705,6 +8705,24 @@ associated <a for="/">element</a>'s
>    <p>Throws a <code>TypeError</code> exception if the associated attribute has no supported tokens defined.
>  </dl>
>  
> +<p>The <a method for=DOMTokenList lt="supports()">supports()</a> method can be used to detect support for {{DOMTokenList}} tokens:
> +<pre class=lang-javascript>
> +var DOMTokenListSupports = function(tokenList, token) {
> +    if (!tokenList || !tokenList.supports) {
> +        return false;
> +    }
> +    try {
> +        return tokenList.supports(token);
> +    } catch (e) {
> +          console.log("The DOMTokenList doesn't have a supported tokens list");
> +    }
> +};
> +
> +var linkSupportsPreload = tokenListSupports(document.createElement("link").relList, supportedToken); // true

When you make this generic, you should probably also make the rest generic and not have `// true`.

Also, the function name used here still doesn't match the one declared earlier on.

---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/pull/144/files#r49065346

Received on Thursday, 7 January 2016 12:29:00 UTC