Path: csiph.com!eternal-september.org!feeder.eternal-september.org!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Performance question Supersedes: <23254603.3H0zayOWXO@PointedEars.de> Date: Sun, 30 Aug 2015 22:21:35 +0200 Organization: PointedEars Software (PES) Lines: 29 Message-ID: <2476408.3rOYMglltH@PointedEars.de> References: <6778316.kWqCXO56M2@PointedEars.de> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: solani.org 1440966306 31587 eJwNyskBwDAIA7CVOGwo4xQa9h8h1Vv00JhEMMDlZlqSWko9LQefpTketJfgHSzD5c+tFB+pC/J4D3k= (30 Aug 2015 20:25:06 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Sun, 30 Aug 2015 20:25:06 +0000 (UTC) User-Agent: KNode/4.14.2 Cancel-Key: sha1:yknejyqJlssQmno5KqncMoF2Bzo= X-User-ID: eJwNwokRwCAMA7CV8jphnEDx/iOUk9KhOBVIRPLZV+hWFOlIlFIu15bDsHFh46s3wem1ckYN1p/LGa1b/AFG6xU8 Cancel-Lock: sha1:lmLNixhlHyK5D68t1tfnQEab9dE= X-NNTP-Posting-Host: eJwNyMkBwCAIBMCW5NgVykGU/ktI5jkwCns7QcdgonfNPwU14o5IaZq3VrzphYWSfDwVJ+N6fB+aETE= Xref: csiph.com comp.lang.javascript:28587 Thomas 'PointedEars' Lahn wrote: > Stefan Ram wrote: >> "Joey@still_Learning.invalid" writes: >>> If I declare a global variable >>>as 'var xxx = document.getElementById('id'),' and use it throughout >>>the script as 'xxx.value or xxx.checked,' does this improve >>>performance? >> >> One does indeed expect such an improvement, but the >> best thing is to measure it under different browsers. > > There is no good reason to believe that omitting a function call in favor > of a variable access would not improve performance. It is unnecessary to > measure this. Also, the variable may be declared, but the reference to the object should be passed to functions and methods by parameter, which should be accessed instead. This shortens the effective scope chain and improves performance again. The module pattern even removes the need for the variable to be declared global. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.