mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-14 00:28:25 -05:00
Merge pull request #494 from johnmanong/default-parameters-last
Default parameters go last.
This commit is contained in:
18
README.md
18
README.md
@@ -556,7 +556,7 @@ Other Style Guides
|
||||
}
|
||||
```
|
||||
|
||||
- [7.8](#7.8) <a name='7.8'></a> Avoid side effects with default parameters
|
||||
- [7.8](#7.8) <a name='7.8'></a> Avoid side effects with default parameters.
|
||||
|
||||
> Why? They are confusing to reason about.
|
||||
|
||||
@@ -572,7 +572,21 @@ Other Style Guides
|
||||
count(); // 3
|
||||
```
|
||||
|
||||
- [7.9](#7.9) <a name='7.9'></a> Never use the Function constructor to create a new function.
|
||||
- [7.9](#7.9) <a name='7.9'></a> Always put default parameters last.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
function handleThings(opts = {}, name) {
|
||||
// ...
|
||||
}
|
||||
|
||||
// good
|
||||
function handleThings(name, opts = {}) {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
- [7.10](#7.10) <a name='7.10'></a> Never use the Function constructor to create a new function.
|
||||
|
||||
> Why? Creating a function in this way evaluates a string similarly to eval(), which opens vulnerabilities.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user