| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/globalThis | [Back] [Original] |
Get to know MDN better
function canMakeHTTPRequest() {
return typeof globalThis.XMLHttpRequest === "function";
}
console.log(canMakeHTTPRequest());
// Expected output (in a browser): true
this
globalThis | |
|---|---|
:
globalThis
JavaScript window, self, frames Web Worker self Node.js global
this undefined Function('return this')() CSP eval() Function
globalThis this () window self this globalThis
:
globalThis globalThis Node globalThis
globalThis iframe Proxy
self global language proposal's "naming" document
globalThis this this this
console.log(window.Math === Math); // true
globalThis Function('return this')() CSP core-js
function check(it) {
// Math
return it && it.Math === Math && it;
}
const globalObject =
check(typeof window === "object" && window) ||
check(typeof self === "object" && self) ||
check(typeof global === "object" && global) ||
// undefined
(function () {
return this;
})() ||
Function("return this")();
if (typeof globalObject.Intl === "undefined") {
// No Intl in this environment; define our own on the global scope
Object.defineProperty(globalObject, "Intl", {
value: {
// Our Intl implementation
},
enumerable: false,
configurable: true,
writable: true,
});
}
globalThis
if (typeof globalThis.Intl === "undefined") {
Object.defineProperty(globalThis, "Intl", {
value: {
// Intl
},
enumerable: false,
configurable: true,
writable: true,
});
}
| ECMAScript 2027 LanguageSpecification # sec-globalthis |
| Web Proxy Viewer | New URL | Original Page |