Aller au contenu

noNewSymbol

Ce contenu n’est pas encore disponible dans votre langue.

Diagnostic Category: lint/correctness/noNewSymbol

Since: v1.0.0

Sources:

Disallow new operators with the Symbol object.

Symbol cannot be instantiated. This results in throwing a TypeError.

var foo = new Symbol('foo');
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’);
----
var bar = Symbol('bar');
function baz() {
function Symbol() { }
new Symbol();
}