Javascript: How to pass objects to window.setTimeout

I was hacking some javascript and wanted to add a timeout to a callback
request (XmlHttpRequest / Ajax).  Note, only async requests
support the abort() function.  Many bad things happen when you try
to abort() a synchronous xmlHttpRequest.  A bit of background… I
create a new xmlHttpRequest object for each callback, so I couldn’t
just use a global variable as my one callback object.

Anyway, I needed to call a function with a parameter via the setTimeout
function.  I soon found out that passing variables/objects to the
specified function is not supported nicely.  So… I used an
anonymous javascript function to do my bidding.

This is the function I wanted to call via the setTimeout function:


function AbortIfCallInProgress(xmlHttpRequest)
{
    switch (xmlHttpRequest.readyState)
    {
        case 1, 2, 3:
            xmlHttpRequest.abort();
            break;

        // Case 4 and 0
        default:
            break;
    }   
}

This is how I called it:


 window.setTimeout(function () { AbortIfCallInProgress(xmlRequest); }, 5000);

Since this is not supported:


 window.setTimeout(‘AbortIfCallInProgress(xmlRequest);’, 5000);