Skip to content

Commit 4ef335e

Browse files
committed
[eslint config] [breaking] require outer IIFE wrapping; flesh out guide section.
There was lots of discussion [here](airbnb#21 (comment)), 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.
1 parent c2fd8fb commit 4ef335e

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,13 +506,17 @@ Other Style Guides
506506
}
507507
```
508508
509-
- [7.2](#7.2) <a name='7.2'></a> Function expressions:
509+
- [7.2](#7.2) <a name='7.2'></a> Immediately invoked function expressions:
510+
511+
> 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.
512+
513+
eslint rules: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html).
510514
511515
```javascript
512516
// immediately-invoked function expression (IIFE)
513-
(() => {
517+
(function () {
514518
console.log('Welcome to the Internet. Please follow me.');
515-
})();
519+
}());
516520
```
517521
518522
- [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.

packages/eslint-config-airbnb/rules/best-practices.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ module.exports = {
108108
// requires to declare all vars on top of their containing scope
109109
'vars-on-top': 2,
110110
// require immediate function invocation to be wrapped in parentheses
111-
'wrap-iife': [2, 'any'],
111+
// http://eslint.org/docs/rules/wrap-iife.html
112+
'wrap-iife': [2, 'outside'],
112113
// require or disallow Yoda conditions
113114
'yoda': 2
114115
}

0 commit comments

Comments
 (0)