Skip to content

Commit

Permalink
Remove autoformatting from IIFE code block
Browse files Browse the repository at this point in the history
  • Loading branch information
yangshun committed Mar 24, 2018
1 parent cec247f commit 2942ae3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Translations/Chinese/questions/javascript-questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ IIFE(Immediately Invoked Function Expressions)代表立即执行函数。 Ja

你可能会用到 `void` 操作符:`void function foo(){ }();`。但是,这种做法是有问题的。表达式的值是`undefined`,所以如果你的 IIFE 有返回值,不要用这种做法。例如:

```js
```
// Don't add JS syntax to this code block to prevent Prettier from formatting it.
const foo = void function bar() { return 'foo'; }();
console.log(foo); // undefined
Expand Down
3 changes: 2 additions & 1 deletion questions/javascript-questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ Here are two ways to fix it that involves adding more brackets: `(function foo()

You might also use `void` operator: `void function foo(){ }();`. Unfortunately, there is one issue with such approach. The evaluation of given expression is always `undefined`, so if your IIFE function returns anything, you can't use it. An example:

```js
```
// Don't add JS syntax to this code block to prevent Prettier from formatting it.
const foo = void function bar() { return 'foo'; }();
console.log(foo); // undefined
Expand Down

0 comments on commit 2942ae3

Please sign in to comment.