Skip to content

noGlobalAssign

诊断类别:lint/suspicious/noGlobalAssign

¥Diagnostic Category: lint/suspicious/noGlobalAssign

自从:v1.5.0

¥Since: v1.5.0

来源:

¥Sources:

禁止分配给原生对象和只读全局变量。

¥Disallow assignments to native objects and read-only global variables.

_JavaScript 环境包含许多内置全局变量,例如浏览器中的 window 和 _Node.js 中的 process。为这些全局变量赋值可能会出现问题,因为它可能会覆盖基本功能。

¥_JavaScript environments contain numerous built-in global variables, such as window in browsers and process in _Node.js. Assigning values to these global variables can be problematic as it can override essential functionality.

¥Examples

¥Invalid

Object = null;
code-block.js:1:1 lint/suspicious/noGlobalAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

A global variable should not be reassigned.

> 1 │ Object = null;
^^^^^^
2 │

Assigning to a global variable can override essential functionality.

window = {};
code-block.js:1:1 lint/suspicious/noGlobalAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

A global variable should not be reassigned.

> 1 │ window = {};
^^^^^^
2 │

Assigning to a global variable can override essential functionality.

undefined = true;
code-block.js:1:1 lint/suspicious/noGlobalAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

A global variable should not be reassigned.

> 1 │ undefined = true;
^^^^^^^^^
2 │

Assigning to a global variable can override essential functionality.

¥Valid

a = 0;
let window;
window = {};

¥Related links