noNewSymbol
诊断类别:lint/correctness/noNewSymbol
¥Diagnostic Category: lint/correctness/noNewSymbol
自从:v1.0.0
¥Since: v1.0.0
来源:
¥Sources:
-
与以下相同:
no-new-symbol
¥Same as:
no-new-symbol
禁止将 new
运算符与 Symbol
对象一起使用。
¥Disallow new
operators with the Symbol
object.
Symbol
无法实例化。这会导致抛出 TypeError
。
¥Symbol
cannot be instantiated. This results in throwing a TypeError
.
¥Examples
¥Invalid
code-block.js:1:11 lint/correctness/noNewSymbol FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Symbol cannot be called as a constructor.
> 1 │ var foo = new Symbol(‘foo’);
│ ^^^^^^^^^^^^^^^^^
2 │
ℹ Unsafe fix: Remove new.
1 │ var·foo·=·new·Symbol(‘foo’);
│ ----
¥Valid
¥Related links