]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/no-func-assign.md
e35b0ed5169ecbade89f469c9918ecc6b7723327
[pve-eslint.git] / eslint / docs / rules / no-func-assign.md
1 # disallow reassigning `function` declarations (no-func-assign)
2
3 JavaScript functions can be written as a FunctionDeclaration `function foo() { ... }` or as a FunctionExpression `var foo = function() { ... };`. While a JavaScript interpreter might tolerate it, overwriting/reassigning a function written as a FunctionDeclaration is often indicative of a mistake or issue.
4
5 ```js
6 function foo() {}
7 foo = bar;
8 ```
9
10 ## Rule Details
11
12 This rule disallows reassigning `function` declarations.
13
14 Examples of **incorrect** code for this rule:
15
16 ```js
17 /*eslint no-func-assign: "error"*/
18
19 function foo() {}
20 foo = bar;
21
22 function foo() {
23 foo = bar;
24 }
25
26 var a = function hello() {
27 hello = 123;
28 };
29 ```
30
31 Examples of **incorrect** code for this rule, unlike the corresponding rule in JSHint:
32
33 ```js
34 /*eslint no-func-assign: "error"*/
35
36 foo = bar;
37 function foo() {}
38 ```
39
40 Examples of **correct** code for this rule:
41
42 ```js
43 /*eslint no-func-assign: "error"*/
44
45 var foo = function () {}
46 foo = bar;
47
48 function foo(foo) { // `foo` is shadowed.
49 foo = bar;
50 }
51
52 function foo() {
53 var foo = bar; // `foo` is shadowed.
54 }
55 ```