mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-25 21:16:21 +00:00
24 lines
360 B
Markdown
24 lines
360 B
Markdown
|
---
|
||
|
id: 828f0c1c-f17a-40fe-9926-50b87a2551a9
|
||
|
title: globalThis
|
||
|
---
|
||
|
|
||
|
# Description
|
||
|
|
||
|
This eases yet another JavaScript pita. Replaces the different global
|
||
|
object names:
|
||
|
|
||
|
- `window` (browser)
|
||
|
- `global` (node)
|
||
|
- `self` (web workers)
|
||
|
|
||
|
with `globalThis`.
|
||
|
|
||
|
# Syntax
|
||
|
|
||
|
``` javascript
|
||
|
if (typeof globalThis.alert === "function") {
|
||
|
globalThis.alert("hi");
|
||
|
}
|
||
|
```
|