[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/globalThis [Back]  [Original]

globalThis - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

globalThis

Baseline

20201

globalThis this

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

HTML WindowProxy

globalThis iframe Proxy

self global language proposal's "naming" document

globalThis this this this

js
console.log(window.Math === Math); // true

1

globalThis Function('return this')() CSP core-js

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")();

Intl

js
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

js
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