mirror of
https://github.com/goldbergyoni/nodebestpractices.git
synced 2025-11-01 18:46:54 +08:00
translate 3-4 to japanese
This commit is contained in:
@ -272,30 +272,30 @@ function someFunction()
|
||||
|
||||
<br/><br/>
|
||||
|
||||
## ![✔] 3.4 Separate your statements properly
|
||||
## ![✔] 3.4 ステートメントを適切に区切る
|
||||
|
||||
No matter if you use semicolons or not to separate your statements, knowing the common pitfalls of improper linebreaks or automatic semicolon insertion, will help you to eliminate regular syntax errors.
|
||||
ステートメントを区切るためにセミコロンを使うか使わないかに関わらず、不適切な改行や自動セミコロン挿入のよくある落とし穴を知っておくことで、通常の構文エラーをなくすことができます。
|
||||
|
||||
**TL;DR:** Use ESLint to gain awareness about separation concerns. [Prettier](https://prettier.io/) or [Standardjs](https://standardjs.com/) can automatically resolve these issues.
|
||||
**TL;DR:** ESLint を使用して、分離の懸念についての認識する。 [Prettier](https://prettier.io/) や [Standardjs](https://standardjs.com/) は、これらの問題を自動的に解決することができます。
|
||||
|
||||
**Otherwise:** As seen in the previous section, JavaScript's interpreter automatically adds a semicolon at the end of a statement if there isn't one, or considers a statement as not ended where it should, which might lead to some undesired results. You can use assignments and avoid using immediate invoked function expressions to prevent most of unexpected errors.
|
||||
**さもないと:** 前のセクションで見たように、JavaScript のインタープリタは、セミコロンがない場合は自動的に文の最後にセミコロンを追加したり、ステートメントが本来あるべき場所で終わっていないとみなしたりすることで、望まない結果になってしまう可能性があります。代入を使用し、即時に呼び出された関数式の使用を避けることで、予期せぬエラーのほとんどを防ぐことができます。
|
||||
|
||||
### Code example
|
||||
### コード例
|
||||
|
||||
```javascript
|
||||
// Do
|
||||
// する
|
||||
function doThing() {
|
||||
// ...
|
||||
}
|
||||
|
||||
doThing()
|
||||
|
||||
// Do
|
||||
// する
|
||||
|
||||
const items = [1, 2, 3]
|
||||
items.forEach(console.log)
|
||||
|
||||
// Avoid — throws exception
|
||||
// 避ける — 例外を投げる
|
||||
const m = new Map()
|
||||
const a = [1,2,3]
|
||||
[...m.values()].forEach(console.log)
|
||||
@ -303,16 +303,16 @@ const a = [1,2,3]
|
||||
> ^^^
|
||||
> SyntaxError: Unexpected token ...
|
||||
|
||||
// Avoid — throws exception
|
||||
const count = 2 // it tries to run 2(), but 2 is not a function
|
||||
// 避ける — 例外を投げる
|
||||
const count = 2 // 2() を実行しようとしますが、2 は関数ではありません
|
||||
(function doSomething() {
|
||||
// do something amazing
|
||||
// 凄いことをする
|
||||
}())
|
||||
// put a semicolon before the immediate invoked function, after the const definition, save the return value of the anonymous function to a variable or avoid IIFEs alltogether
|
||||
// 直ちに呼び出された関数の前、const 定義の後にセミコロンを置く、匿名関数の戻り値を変数に保存する、あるいは IIFE を完全に回避する
|
||||
```
|
||||
|
||||
🔗 [**Read more:** "Semi ESLint rule"](https://eslint.org/docs/rules/semi)
|
||||
🔗 [**Read more:** "No unexpected multiline ESLint rule"](https://eslint.org/docs/rules/no-unexpected-multiline)
|
||||
🔗 [**さらに読む:** "準 ESLint ルール"](https://eslint.org/docs/rules/semi)
|
||||
🔗 [**さらに読む:** "予期せぬ複数行の ESLint ルールがない"](https://eslint.org/docs/rules/no-unexpected-multiline)
|
||||
|
||||
<br/><br/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user