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