mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-14 16:37:54 -05:00
[eslint config] [breaking] require outer IIFE wrapping; flesh out guide section.
There was lots of discussion [here](https://github.com/airbnb/javascript/issues/21#issuecomment-10203921), but now that we have both a modern build system and an eslint rule requiring terminating semicolons, the concerns with the “crockford” style no longer apply.
This commit is contained in:
10
README.md
10
README.md
@@ -506,13 +506,17 @@ Other Style Guides
|
||||
}
|
||||
```
|
||||
|
||||
- [7.2](#7.2) <a name='7.2'></a> Function expressions:
|
||||
- [7.2](#7.2) <a name='7.2'></a> Immediately invoked function expressions:
|
||||
|
||||
> Why? An immediately invoked function expression is a single unit - wrapping both it, and its invocation parens, in parens, cleanly expresses this. Note that in a world with modules everywhere, you almost never need an IIFE.
|
||||
|
||||
eslint rules: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html).
|
||||
|
||||
```javascript
|
||||
// immediately-invoked function expression (IIFE)
|
||||
(() => {
|
||||
(function () {
|
||||
console.log('Welcome to the Internet. Please follow me.');
|
||||
})();
|
||||
}());
|
||||
```
|
||||
|
||||
- [7.3](#7.3) <a name='7.3'></a> Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears.
|
||||
|
||||
@@ -108,7 +108,8 @@ module.exports = {
|
||||
// requires to declare all vars on top of their containing scope
|
||||
'vars-on-top': 2,
|
||||
// require immediate function invocation to be wrapped in parentheses
|
||||
'wrap-iife': [2, 'any'],
|
||||
// http://eslint.org/docs/rules/wrap-iife.html
|
||||
'wrap-iife': [2, 'outside'],
|
||||
// require or disallow Yoda conditions
|
||||
'yoda': 2
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user