HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Funny little code optimisation (#news_170) - Comments

Login / Search

 [ Join | More ]
 

Funny little code optimisation

Posted 09 August 2009, 12:53 AM
I'm in the middle of reviewing a developers code. This amused me…

Code

      var url='';
      if(document.getElementById('file'+number))
      {
         url=document.getElementById('file'+number).value;
      }
      else
      {
         if (filename!='')
         {
            url=filename;
         }
      }

because it is exactly equivalent in behaviour to…

Read more


Ain't quite optimized yet.

Avatar
Optimization would be when you can avoid the second evaluation of "document.getElementById('file'+number)":

      var url=filename;
      var obj=document.getElementById('file'+number);
      if(obj)
      {
         url=obj.value;
      }

Avatar
Very true :).

There are too many online users to list.
Control functions:

Quick reply   Contract

Your name:
Your message: