Skip to content

Commit aacaca8

Browse files
committed
Merge pull request airbnb#643 from AlicanC/split-never-mutate-parameters
[Docs] Make no-param-reassign a separate section.
2 parents 8c241be + 6d9a787 commit aacaca8

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,23 @@ Other Style Guides
631631
632632
- [7.12](#7.12) <a name="7.12"></a> Never mutate parameters.
633633
634-
> Why? Overwriting parameters can lead to unexpected behavior, especially when accessing the `arguments` object. Manipulating objects passed in as parameters can cause unwanted variable side effects in the original caller.
634+
> Why? Manipulating objects passed in as parameters can cause unwanted variable side effects in the original caller.
635+
636+
```javascript
637+
// bad
638+
function f1(obj) {
639+
obj.key = 1;
640+
};
641+
642+
// good
643+
function f2(obj) {
644+
const key = Object.prototype.hasOwnProperty.call(obj, 'key') ? obj.key : 1;
645+
};
646+
```
647+
648+
- [7.13](#7.13) <a name="7.13"></a> Never reassign parameters.
649+
650+
> Why? Reassigning parameters can lead to unexpected behavior, especially when accessing the `arguments` object. It can also cause optimization issues, especially in V8.
635651
636652
eslint rules: [`no-param-reassign`](http://eslint.org/docs/rules/no-param-reassign.html).
637653
@@ -645,21 +661,13 @@ Other Style Guides
645661
if (!a) { a = 1; }
646662
}
647663

648-
function f3(obj) {
649-
obj.key = 1;
650-
};
651-
652664
// good
653-
function f4(a) {
665+
function f3(a) {
654666
const b = a || 1;
655667
}
656668

657-
function f5(a = 1) {
669+
function f4(a = 1) {
658670
}
659-
660-
function f6(obj) {
661-
const key = Object.prototype.hasOwnProperty.call(obj, 'key') ? obj.key : 1;
662-
};
663671
```
664672
665673
**[⬆ back to top](#table-of-contents)**

0 commit comments

Comments
 (0)