Skip navigation.

My comments on ...

... everything bothering me

The better way of Capability Detection

, ,

In response to Crisp's post about "capability detection" (and his comment system, that ate most of my messages...):

The goal was to optimize the code provided so the "if" statements were not part of the function anymore.

The code wrapped around the "finally" construct might stand alone, and I'm sure the code could be otherwise shortened, but I think this should work all in all...

if (!window.XMLHttpRequest)
{
     var temp;
     var types = [
         'MSXML2.XMLHTTP.6.0',
         'MSXML2.XMLHTTP.3.0'
     ];
 
     for (var i = 0; i < types.length; i++)
     {
         try
         {
             temp = function(){return new ActiveXObject(types[i])};
             void(temp());
         }
         catch(e) {temp = null;}
         finally {if(temp) break;}
     }
     window.XMLHttpRequest = temp || function(){return undefined};
}

The better way of Capability Detection, Part 2

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.

December 2009
M T W T F S S
November 2009January 2010
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31