Interestingly, the standard XMLHttpRequest object type is in JavaScript. I found different results depending on the engine.
In Firefox and Chrome:
typeof XMLHttpRequest //=> "function"
In Safari:
typeof XMLHttpRequest //=> "object"
The W3C specification uses the interface keyword to define XMLHttpRequest , which is not used in practice :
[Constructor(optional XMLHttpRequestOptions options)] interface XMLHttpRequest : XMLHttpRequestEventTarget {
The definition of MDN states that:
XMLHttpRequest is a JavaScript object ...
But Firefox returns "function" , so the term is fuzzy. The definition also states that:
Now it is standardized in W3C.
I looked a little more here and there, but there is no final answer β’. Whether there is a?
Beyond this point, some additional background
Question Context
I just fixed the error in this code:
if (typeof XMLHttpRequest === "function") { // do something }
The error only appeared in Safari 7 so far (no tests in other versions). The code works fine in Firefox and Chrome. Fixed:
if (typeof XMLHttpRequest !== "undefined") { // do something }
The problem came from the fact that typeof XMLHttpRequest is the same everywhere ...
Eric Platon
source share