]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/no-new-symbol.md
first commit
[pve-eslint.git] / eslint / docs / rules / no-new-symbol.md
1 # Disallow Symbol Constructor (no-new-symbol)
2
3 `Symbol` is not intended to be used with the `new` operator, but to be called as a function.
4
5 ```js
6 var foo = new Symbol("foo");
7 ```
8
9 This throws a `TypeError` exception.
10
11 ## Rule Details
12
13 This rule is aimed at preventing the accidental calling of `Symbol` with the `new` operator.
14
15 ## Examples
16
17 Examples of **incorrect** code for this rule:
18
19 ```js
20 /*eslint no-new-symbol: "error"*/
21 /*eslint-env es6*/
22
23 var foo = new Symbol('foo');
24 ```
25
26 Examples of **correct** code for this rule:
27
28 ```js
29 /*eslint no-new-symbol: "error"*/
30 /*eslint-env es6*/
31
32 var foo = Symbol('foo');
33
34
35 // Ignores shadowed Symbol.
36 function bar(Symbol) {
37 const baz = new Symbol("baz");
38 }
39
40 ```
41
42 ## When Not To Use It
43
44 This rule should not be used in ES3/5 environments.
45
46 ## Further Reading
47
48 * [Symbol Objects specification](https://www.ecma-international.org/ecma-262/6.0/#sec-symbol-objects)