Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsfeed.straub-nv.de!noris.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="ISO-8859-1" Message-ID: <6590377.0brVofrJPU@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Wed, 24 Oct 2012 21:27:57 +0200 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 7Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. <722e889us0ep0mra233907giq2nnolqhge@4ax.com> Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 35 NNTP-Posting-Date: 24 Oct 2012 21:27:58 CEST NNTP-Posting-Host: a115b9cb.newsspool3.arcor-online.net X-Trace: DXC=J53bM;oanh]aoembcbF;DQMcF=Q^Z^V3X4Fo<]lROoRQ8kFKP40i@2K255T[=?7jWd<>\8T X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:16837 Patricia Shanahan wrote: > On 10/24/2012 12:35 AM, Evertjan. wrote: >> Well, you are looking the wrong way, it seems, >> these oprators, especially || are regulary used >> in Javascript to prevent errors when a function is not available >> on a platform, so at runtime, when you as a programmer are not available. >> >> var r = aDOMfunction || aDOMfunction("23px"); > > I've looked at this several times, and think it should be "&&" not "||". > > "||" evaluates the right hand side if the left hand side is not truthy, > in this case if the function does not exist. > > Surely one wants to evaluate the right hand side if, and only if, > aDOMfunction *does* exist. That is what "&&" would do. Correct. It is insufficient and error-prone a feature test, though: A true- value does not need to be callable, and a host object can throw an exception on type conversion or even non-calling read access. Search for implementations of `isNativeMethod' and `isHostMethod' instead (you can find one in JSX:object.js). `||' is useful for implementing default values, but slightly overkill for default parameter values (unless they are not used left-hand side of the assignment). PointedEars -- realism: HTML 4.01 Strict evangelism: XHTML 1.0 Strict madness: XHTML 1.1 as application/xhtml+xml -- Bjoern Hoehrmann