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

globalThis - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

globalThis

20201

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

HTML WindowProxy

globalThis iframe Proxy

self global language proposal's "naming" document

globalThis Function('return this')() CSP es6-shim

js
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

js
if (typeof globalThis.setTimeout !== "function") {
  //   setTimeout 
}

ECMAScript 2027 LanguageSpecification
# sec-globalthis


Web Proxy Viewer  |  New URL  |  Original Page