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


Groups > comp.lang.javascript > #15079

Re: Best way to feature-test?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!newsfeed.straub-nv.de!uucp.gnuu.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-ID <2169875.p79QOsc7RG@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Organization PointedEars Software (PES)
Date Mon, 16 Jul 2012 21:29:49 +0200
User-Agent KNode/4.4.11
Content-Transfer-Encoding 8Bit
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
Subject Re: Best way to feature-test?
Newsgroups comp.lang.javascript
References <9279c95c-914c-4a92-aa23-495f81bccc1a@googlegroups.com> <ju0kh6$itl$1@dont-email.me>
Followup-To comp.lang.javascript
MIME-Version 1.0
Lines 79
NNTP-Posting-Date 16 Jul 2012 21:29:51 CEST
NNTP-Posting-Host ee864b1a.newsspool4.arcor-online.net
X-Trace DXC=fR7e_5EURKofF8a^:6>b7e4IUK<Cl32<a4Fo<]lROoRa8kF<OcfhCOkLf0HJ8I\J]nDZm8W4\YJNlT<8F<]0D<`i>4UH3dlTk?eCF@]BF`?gTc
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:15079

Followups directed to: comp.lang.javascript

Show key headers only | View raw


Gregor Kofler wrote:

> Am 2012-07-16 02:50, perryv@gmail.com meinte:
>> […] 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>
> […]

I have since realized not only the usefulness of having a method that can 
deal with separate object reference and property names instead of a `typeof' 
result (isMethod), but also of having a separate method for methods of 
host and native objects (isNativeMethod) each. (jsx.object.isMethodType(), 
formerly isMethodType(), is still supported but has been marked deprecated 
accordingly.  It may not be supported in future revisions.)

Therefore, JSX:object.js contains jsx.object.isMethod()) (formerly 
isMethod()) since at least revision 123 (2008-05-29), and 
jsx.object.isHostMethod() (alias for .isMethod()) and 
jsx.object.isNativeMethod() (wrapper for .isMethod()) since revision 234 
(2011-12-12).  

jsx.object.areNativeMethods(), jsx.object.areHostMethods(), and 
jsx.object.areMethods(), the latter of which has been been introduced in 
revision 146 (2009-07-16), are aliases for those methods, respectively.  As 
an extension to the methods in David's library (so to speak), they also 
support calls of the form

  if (jsx.object.isHostMethod(window, "document", "write"))

(accepts an arbitrary number of arguments) which prevents you from having to 
write

  if (typeof window.document != "undefined"
      && jsx.object.isHostMethod(window.document, "write"))

and

  if (jsx.object.areHostMethods(document, ["open", "write", "close"]))

which prevents you from having to write

  var _isHostMethod = jsx.object.isHostMethod;
  if (_isHostMethod(document, "open")
      && _isHostMethod(document, "write")
      && _isHostMethod(document, "close"))

which is not only tedious to write but also inefficient by comparison.

See 
<http://PointedEars.de/websvn/filedetails.php?repname=JSX&path=%2Ftrunk%2Fobject.js> 
for more.


PointedEars
-- 
> If you get a bunch of authors […] that state the same "best practices"
> in any programming language, then you can bet who is wrong or right...
Not with javascript. Nonsense propagates like wildfire in this field.
  -- Richard Cornford, comp.lang.javascript, 2011-11-14

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