]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/new-parens.md
0b2a49b7e764c4c3d3011f47d4d1db17688635ca
[pve-eslint.git] / eslint / docs / rules / new-parens.md
1 # require parentheses when invoking a constructor with no arguments (new-parens)
2
3 JavaScript allows the omission of parentheses when invoking a function via the `new` keyword and the constructor has no arguments. However, some coders believe that omitting the parentheses is inconsistent with the rest of the language and thus makes code less clear.
4
5 ```js
6 var person = new Person;
7 ```
8
9 ## Rule Details
10
11 This rule can enforce or disallow parentheses when invoking a constructor with no arguments using the `new` keyword.
12
13 ## Options
14
15 This rule takes one option.
16
17 - `"always"` enforces parenthesis after a new constructor with no arguments (default)
18 - `"never"` enforces no parenthesis after a new constructor with no arguments
19
20 ### always
21
22 Examples of **incorrect** code for this rule with the `"always"` option:
23
24 ```js
25 /*eslint new-parens: "error"*/
26
27 var person = new Person;
28 var person = new (Person);
29 ```
30
31 Examples of **correct** code for this rule with the `"always"` option:
32
33 ```js
34 /*eslint new-parens: "error"*/
35
36 var person = new Person();
37 var person = new (Person)();
38 ```
39
40 ### never
41
42 Examples of **incorrect** code for this rule with the `"never"` option:
43
44 ```js
45 /*eslint new-parens: ["error", "never"]*/
46
47 var person = new Person();
48 var person = new (Person)();
49 ```
50
51 Examples of **correct** code for this rule with the `"never"` option:
52
53 ```js
54 /*eslint new-parens: ["error", "never"]*/
55
56 var person = new Person;
57 var person = (new Person);
58 var person = new Person("Name");
59 ```