wiki/content/20201116170538-globalthis.md

375 B

date id title
20201116 828f0c1c-f17a-40fe-9926-50b87a2551a9 globalThis

Description

This eases yet another JavaScript pita. Replaces the different global object names:

  • window (browser)
  • global (node)
  • self (web workers)

with globalThis.

Syntax

if (typeof globalThis.alert === "function") {
  globalThis.alert("hi");
}