| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/globalThis | [Back] [Original] |
Get to know MDN better
globalThis this global object
function canMakeHTTPRequest() {
return typeof globalThis.XMLHttpRequest === "function";
}
console.log(canMakeHTTPRequest());
// Expected output (in a browser): true
globalThis | |
|---|---|
globalThis
JavaScript Web windowself frames Web Workers self Node.js global
this this undefined Function('return this')()eval()CSPFunction
globalThis this window self globalThis this globalThis
globalThis iframe Proxy
self global language proposal's "naming" document
globalThis Function('return this')() CSP es6-shim
var getGlobal = function () {
if (typeof self !== "undefined") {
return self;
}
if (typeof window !== "undefined") {
return window;
}
if (typeof global !== "undefined") {
return global;
}
throw new Error("unable to locate global object");
};
var globals = getGlobal();
if (typeof globals.setTimeout !== "function") {
// setTimeout
}
globalThis
if (typeof globalThis.setTimeout !== "function") {
// setTimeout
}
| ECMAScript 2027 LanguageSpecification # sec-globalthis |
| Web Proxy Viewer | New URL | Original Page |