[ong] Default parameters go last.

This commit is contained in:
johnmanong
2015-08-30 14:19:20 -04:00
parent 13d782f82e
commit 701cbb954d

View File

@@ -556,7 +556,21 @@ 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> Always put default parameters last.
```javascript
// bad
function handleThings(opts = {}, name) {
// ...
}
// good
function handleThings(name, opts = {}) {
// ...
}
```
- [7.9](#7.9) <a name='7.9'></a> Avoid side effects with default parameters.
> Why? They are confusing to reason about.
@@ -572,7 +586,7 @@ 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.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.