mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-14 08:38:08 -05:00
Update to warn against Function constructor
Added section 7.9 to warn against using the Function creator, as it opens similar vulnerabilities as eval. Originally suggested in pull request #395. No other lines were edited or removed.
This commit is contained in:
@@ -567,6 +567,14 @@
|
||||
count(); // 3
|
||||
```
|
||||
|
||||
- [7.9](#7.9) <a name='7.9'></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.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
var add = new Function("a", "b", "return a + b");
|
||||
```
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
|
||||
Reference in New Issue
Block a user