Removed the parts about browser compatibility
`globalThis` is now supported in all major browsers, see link https://caniuse.com/#search=globalThis
This commit is contained in:
parent
b0c5dad519
commit
b946ee04c9
1 changed files with 2 additions and 2 deletions
|
@ -5,7 +5,7 @@ The global object provides variables and functions that are available anywhere.
|
||||||
|
|
||||||
In a browser it is named `window`, for Node.js it is `global`, for other environments it may have another name.
|
In a browser it is named `window`, for Node.js it is `global`, for other environments it may have another name.
|
||||||
|
|
||||||
Recently, `globalThis` was added to the language, as a standardized name for a global object, that should be supported across all environments. In some browsers, namely non-Chromium Edge, `globalThis` is not yet supported, but can be easily polyfilled.
|
Recently, `globalThis` was added to the language, as a standardized name for a global object, that should be supported across all environments. It's supported in all major browsers.
|
||||||
|
|
||||||
We'll use `window` here, assuming that our environment is a browser. If your script may run in other environments, it's better to use `globalThis` instead.
|
We'll use `window` here, assuming that our environment is a browser. If your script may run in other environments, it's better to use `globalThis` instead.
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ if (!window.Promise) {
|
||||||
That includes JavaScript built-ins, such as `Array` and environment-specific values, such as `window.innerHeight` -- the window height in the browser.
|
That includes JavaScript built-ins, such as `Array` and environment-specific values, such as `window.innerHeight` -- the window height in the browser.
|
||||||
- The global object has a universal name `globalThis`.
|
- The global object has a universal name `globalThis`.
|
||||||
|
|
||||||
...But more often is referred by "old-school" environment-specific names, such as `window` (browser) and `global` (Node.js). As `globalThis` is a recent proposal, it's not supported in non-Chromium Edge (but can be polyfilled).
|
...But more often is referred by "old-school" environment-specific names, such as `window` (browser) and `global` (Node.js).
|
||||||
- We should store values in the global object only if they're truly global for our project. And keep their number at minimum.
|
- We should store values in the global object only if they're truly global for our project. And keep their number at minimum.
|
||||||
- In-browser, unless we're using [modules](info:modules), global functions and variables declared with `var` become a property of the global object.
|
- In-browser, unless we're using [modules](info:modules), global functions and variables declared with `var` become a property of the global object.
|
||||||
- To make our code future-proof and easier to understand, we should access properties of the global object directly, as `window.x`.
|
- To make our code future-proof and easier to understand, we should access properties of the global object directly, as `window.x`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue