setInterval(requestQueue.callQueue, 100);
Peels off the callQueue
method from requestQueue
and passes it to setInterval
. Consequently callQueue
has no reference to requestQueue
; when it is called back, this
will be set to window
not requestQueue
so the attempt to evaluate this.callToArray.length
will cause an error.
this
in JavaScript does not work in the way you would expect from any other language. See this question for an explanation. If you only have one requestQueue
instance you can just reference that instead of using this
, otherwise you'll need to look into function binding or a closure.
Incidentally I'd not recommend UA-string-sniffing for detecting the right XHR object to use. Try feature-sniffing instead:
var r= window.XMLHttpRequest? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
(this would also use native XMLHttp on IE7+ where enabled, potentially avoiding an ActiveX prompt.)