π Prefer globalThis over window, self, and global.
πΌ This rule is enabled in the following configs: β
recommended, βοΈ unopinionated.
π§ This rule is automatically fixable by the --fix CLI option.
This rule will enforce the use of globalThis over window, self, and global.
However, there are several exceptions that remain permitted:
- Certain window-specific APIs, such as
window.innerHeight - Window-specific events, such as
window.addEventListener('resize') - Computed property access on
window, such aswindow[foo]
The complete list of permitted APIs can be found in the rule's source code.
// β
window;
// β
globalThis;// β
window.foo;
// β
globalThis.foo;// β
global;
// β
globalThis;// β
global.foo;
// β
globalThis.foo;// β
const {foo} = window;
// β
const {foo} = globalThis;// β
window.navigator;
// β
globalThis.navigator;// β
window.location;
// β
globalThis.location;// β
window.innerWidth;
// β
window.innerHeight;// β
window.addEventListener('click', () => {});
// β
globalThis.addEventListener('click', () => {});
// β
window.addEventListener('resize', () => {});
// β
window.addEventListener('load', () => {});
// β
window.addEventListener('unload', () => {});