Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #15065

Re: Best way to feature-test?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From Gregor Kofler <usenet@gregorkofler.com>
Newsgroups comp.lang.javascript
Subject Re: Best way to feature-test?
Date Mon, 16 Jul 2012 10:48:37 +0200
Organization A noiseless patient Spider
Lines 37
Message-ID <ju0kh6$itl$1@dont-email.me> (permalink)
References <9279c95c-914c-4a92-aa23-495f81bccc1a@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Mon, 16 Jul 2012 08:48:38 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="743f91444812977df008257371f61756"; logging-data="19381"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19PmrHXKxNH9XieZeUG1mXhx6ugO2rsP04="
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1
In-Reply-To <9279c95c-914c-4a92-aa23-495f81bccc1a@googlegroups.com>
Cancel-Lock sha1:+qQeBVjBW8DKw+T1BdUqyNltBxk=
Xref csiph.com comp.lang.javascript:15065

Show key headers only | View raw


Am 2012-07-16 02:50, perryv@gmail.com meinte:
> Hi everyone,
>
> I've been using the following technique to detect if a certain functionality is supported by a browser:
>
>
> if(document.someFunctionality) {
>      // Use someFunctionality
> }
>
> But lately, I've been reading that "document", "window" and other browser objects are "host objects", and host objects have their own rules and behaviors that depend on the browser and the platform. So it's possible that merely testing "document.someFunctionality" can throw an exception in some browser on some platform.
>
> So, in order to cover those cases, is it reasonable to do the following?
>
> if(typeof document.someProperty != 'undefined') {
>      // Go ahead and use the property
> }
>
> if(typeof document.someFunction == 'function') {
>      // Go ahead and invoke "document.someFunction()"
> }
>
> Or is it overkill?

Quite the contrary.

Some links for further reading:

<http://www.cinsoft.net/host.html>
<http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting>


Gregor


-- 
http://vxweb.net

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Best way to feature-test? perryv@gmail.com - 2012-07-15 17:50 -0700
  Re: Best way to feature-test? perryv@gmail.com - 2012-07-15 17:54 -0700
  Re: Best way to feature-test? Gregor Kofler <usenet@gregorkofler.com> - 2012-07-16 10:48 +0200
    Re: Best way to feature-test? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-07-16 21:29 +0200
  Re: Best way to feature-test? Ivan The Not-So-Bad <1suf41n@yahoo.com> - 2012-07-16 13:49 +0000
    Re: Best way to feature-test? Tim Down <timdown@gmail.com> - 2012-07-16 08:42 -0700
      Re: Best way to feature-test? Ivan The Not-So-Bad <1suf41n@yahoo.com> - 2012-07-16 17:35 +0000
  Re: Best way to feature-test? Jim T. <x@y.z> - 2012-07-18 13:22 -0400
    Re: Best way to feature-test? Jim T. <x@y.z> - 2012-07-18 13:24 -0400

csiph-web