noGlobalIsFinite
诊断类别:lint/suspicious/noGlobalIsFinite
¥Diagnostic Category: lint/suspicious/noGlobalIsFinite
自从:v1.0.0
¥Since: v1.0.0
使用 Number.isFinite
而不是全局 isFinite
。
¥Use Number.isFinite
instead of global isFinite
.
Number.isFinite()
和 isFinite()
没有相同的行为。当 isFinite()
的参数不是数字时,首先将值强制转换为数字。Number.isFinite()
不执行此强制。因此,这是一种更可靠的方法来测试数字是否有限。
¥Number.isFinite()
and isFinite()
do not have the same behavior.
When the argument to isFinite()
is not a number, the value is first coerced to a number.
Number.isFinite()
does not perform this coercion.
Therefore, it is a more reliable way to test whether a number is finite.
¥Examples
¥Invalid
code-block.js:1:1 lint/suspicious/noGlobalIsFinite FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ isFinite is unsafe. It attempts a type coercion. Use Number.isFinite instead.
> 1 │ isFinite(false); // true
│ ^^^^^^^^
2 │
ℹ See the MDN documentation for more details.
ℹ Unsafe fix: Use Number.isFinite instead.
1 │ - isFinite(false);·//·true
1 │ + Number.isFinite(false);·//·true
2 2 │
¥Valid
¥Related links