@@ -118,8 +118,8 @@ setTimeout(blastOff, 86400000);
118118
119119** Good:**
120120``` javascript
121- // Declare them as capitalized `const` globals .
122- // それらを大文字のグローバルな`const`をして定義します 。
121+ // Declare them as capitalized named constants .
122+ // それらを大文字の名前付き定数として宣言してください 。
123123const MILLISECONDS_IN_A_DAY = 86400000 ;
124124
125125setTimeout (blastOff, MILLISECONDS_IN_A_DAY );
@@ -238,7 +238,7 @@ function createMicrobrewery(name) {
238238
239239** Good:**
240240``` javascript
241- function createMicrobrewery (breweryName = ' Hipster Brew Co.' ) {
241+ function createMicrobrewery (name = ' Hipster Brew Co.' ) {
242242 // ...
243243}
244244
@@ -417,6 +417,14 @@ function parseBetterJSAlternative(code) {
417417
418418** Good:**
419419``` javascript
420+ function parseBetterJSAlternative (code ) {
421+ const tokens = tokenize (code);
422+ const ast = lexer (tokens);
423+ ast .forEach ((node ) => {
424+ // parse...
425+ });
426+ }
427+ 420428function tokenize (code ) {
421429 const REGEXES = [
422430 // ...
@@ -441,14 +449,6 @@ function lexer(tokens) {
441449
442450 return ast;
443451}
444- 445- function parseBetterJSAlternative (code ) {
446- const tokens = tokenize (code);
447- const ast = lexer (tokens);
448- ast .forEach ((node ) => {
449- // parse...
450- });
451- }
452452```
453453** [ ⬆ back to top] ( #table-of-contents ) **
454454
@@ -531,22 +531,20 @@ function showEmployeeList(employees) {
531531 const expectedSalary = employee .calculateExpectedSalary ();
532532 const experience = employee .getExperience ();
533533
534- let portfolio;
534+ const data = {
535+ expectedSalary,
536+ experience
537+ };
538+ 535539 switch (employee .type ) {
536540 case ' manager' :
537- portfolio = employee .getMBAProjects ();
541+ data . portfolio = employee .getMBAProjects ();
538542 break ;
539543 case ' developer' :
540- portfolio = employee .getGithubLink ();
544+ data . githubLink = employee .getGithubLink ();
541545 break ;
542546 }
543547
544- const data = {
545- expectedSalary,
546- experience,
547- portfolio
548- };
549- 550548 render (data);
551549 });
552550}
@@ -806,11 +804,11 @@ class SuperArray extends Array {
806804### Favor functional programming over imperative programming
807805### 手続き型プログラミングより関数型プログラミングを優先する
808806JavaScript isn't a functional language in the way that Haskell is, but it has
809- a functional flavor to it. Functional languages are cleaner and easier to test.
807+ a functional flavor to it. Functional languages can be cleaner and easier to test.
810808Favor this style of programming when you can.
811809
812810JavaScriptは、Haskellがやっているような関数型言語ではありませんが、部分的にその機能があります。
813- 関数型言語は簡潔で用意にテストすることができます 。あなたができる時は、このプログラミングスタイルを優先してください。
811+ 関数型言語はよりクリーンでテストしやすいものになります 。あなたができる時は、このプログラミングスタイルを優先してください。
814812
815813** Bad:**
816814``` javascript
@@ -855,11 +853,9 @@ const programmerOutput = [
855853 }
856854];
857855
858- const INITIAL_VALUE = 0 ;
859- 860856const totalOutput = programmerOutput
861- .map (( programmer ) => programmer .linesOfCode )
862- .reduce ((acc , linesOfCode ) => acc + linesOfCode, INITIAL_VALUE );
857+ .map (output => output .linesOfCode )
858+ .reduce ((totalLines , lines ) => totalLines + lines );
863859```
864860** [ ⬆ back to top] ( #table-of-contents ) **
865861
@@ -1008,7 +1004,7 @@ function travelToTexas(vehicle) {
10081004
10091005### Avoid type-checking (part 2)
10101006### 型チェックを避ける (part 2)
1011- If you are working with basic primitive values like strings, integers, and arrays ,
1007+ If you are working with basic primitive values like stringsand integers ,
10121008and you can't use polymorphism but you still feel the need to type-check,
10131009you should consider using TypeScript. It is an excellent alternative to normal
10141010JavaScript, as it provides you with static typing on top of standard JavaScript
@@ -1018,7 +1014,7 @@ doesn't make up for the lost readability. Keep your JavaScript clean, write
10181014good tests, and have good code reviews. Otherwise, do all of that but with
10191015TypeScript (which, like I said, is a great alternative!).
10201016
1021- もし、あなたが文字列、数値、配列のような基本的なプリミティブな値を扱っていて 、ポリモーフィズムを使えない、しかしまだタイプチェックが必要だと感じている場合。
1017+ もし、あなたが文字列、数値のような基本的なプリミティブな値を扱っていて 、ポリモーフィズムを使えない、しかしまだタイプチェックが必要だと感じている場合。
10221018TypeScriptの利用を検討してみてください。
10231019これは標準のJavaScript構文の上に静的な型を提供するので、通常のJavaScriptに変わる優れた代替品です。
10241020通常のJavaScript手作業のタイプチェックの問題は、偽物の型安全を得るために、あまりにも多くの余計な構文が必要なことです。これらは失った可読性を補うようなものではありません。
@@ -1327,10 +1323,10 @@ and you can chain further class methods onto it.
13271323** Bad:**
13281324``` javascript
13291325class Car {
1330- constructor () {
1331- this .make = ' Honda ' ;
1332- this .model = ' Accord ' ;
1333- this .color = ' white ' ;
1326+ constructor (make , model , color ) {
1327+ this .make = make ;
1328+ this .model = model ;
1329+ this .color = color ;
13341330 }
13351331
13361332 setMake (make ) {
@@ -1350,20 +1346,18 @@ class Car {
13501346 }
13511347}
13521348
1353- const car = new Car ();
1349+ const car = new Car (' Ford ' , ' F-150 ' , ' red ' );
13541350car .setColor (' pink' );
1355- car .setMake (' Ford' );
1356- car .setModel (' F-150' );
13571351car .save ();
13581352```
13591353
13601354** Good:**
13611355``` javascript
13621356class Car {
1363- constructor () {
1364- this .make = ' Honda ' ;
1365- this .model = ' Accord ' ;
1366- this .color = ' white ' ;
1357+ constructor (make , model , color ) {
1358+ this .make = make ;
1359+ this .model = model ;
1360+ this .color = color ;
13671361 }
13681362
13691363 setMake (make ) {
@@ -1395,10 +1389,8 @@ class Car {
13951389 }
13961390}
13971391
1398- const car = new Car ()
1392+ const car = new Car (' Ford ' , ' F-150 ' , ' red ' );
13991393 .setColor (' pink' )
1400- .setMake (' Ford' )
1401- .setModel (' F-150' )
14021394 .save ();
14031395```
14041396** [ ⬆ back to top] ( #table-of-contents ) **
@@ -1981,7 +1973,7 @@ in addition to having a great testing framework, you also need to use a
19811973何をもって十分な量であるかを決定することはチームに任されていますが、(すべての文や分岐に対して)100%のカバレッジを持つことは、非常に高い信頼性と開発者の安心を達成する方法です。
19821974この意味することは、あなたは良いテストフレームワークを持つことに加えて、[ 良いカバレッジツール] ( http://gotwarlost.github.io/istanbul/ ) も使うことが必要だということです。
19831975
1984- There's no excuse to not write tests. There's [ plenty of good JS test frameworks] ( http://jstherightway.org/#testing-tools ) , so find one that your team prefers.
1976+ There's no excuse to not write tests. There are [ plenty of good JS test frameworks] ( http://jstherightway.org/#testing-tools ) , so find one that your team prefers.
19851977When you find one that works for your team, then aim to always write tests
19861978for every new feature/module you introduce. If your preferred method is
19871979Test Driven Development (TDD), that is great, but the main point is to just
@@ -2261,8 +2253,8 @@ JavaScriptには型がありません。そのため大文字は変数や関数
22612253const DAYS_IN_WEEK = 7 ;
22622254const daysInMonth = 30 ;
22632255
2264- const songs = [' Back In Black' , ' Stairway to Heaven' , ' Hey Jude' ];
2265- const Artists = [' ACDC' , ' Led Zeppelin' , ' The Beatles' ];
2256+ const SONGS = [' Back In Black' , ' Stairway to Heaven' , ' Hey Jude' ];
2257+ const ARTISTS = [' ACDC' , ' Led Zeppelin' , ' The Beatles' ];
22662258
22672259function eraseDatabase () {}
22682260function restore_database () {}
@@ -2529,10 +2521,15 @@ This is also available in other languages:
25292521 - [ beginor/clean-code-javascript] ( https://github.com/beginor/clean-code-javascript )
25302522 - ![ de] ( https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Germany.png ) ** German** : [ marcbruederlin/clean-code-javascript] ( https://github.com/marcbruederlin/clean-code-javascript )
25312523 - ![ kr] ( https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/South-Korea.png ) ** Korean** : [ qkraudghgh/clean-code-javascript-ko] ( https://github.com/qkraudghgh/clean-code-javascript-ko )
2524+ - ![ pl] ( https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Poland.png ) ** Polish** : [ greg-dev/clean-code-javascript-pl] ( https://github.com/greg-dev/clean-code-javascript-pl )
25322525 - ![ ru] ( https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Russia.png ) ** Russian** :
25332526 - [ BoryaMogila/clean-code-javascript-ru/] ( https://github.com/BoryaMogila/clean-code-javascript-ru/ )
25342527 - [ maksugr/clean-code-javascript] ( https://github.com/maksugr/clean-code-javascript )
25352528 - ![ vi] ( https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Vietnam.png ) ** Vietnamese** : [ hienvd/clean-code-javascript/] ( https://github.com/hienvd/clean-code-javascript/ )
25362529 - ![ ja] ( https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Japan.png ) ** Japanese** : [ mitsuruog/clean-code-javascript/] ( https://github.com/mitsuruog/clean-code-javascript/ )
2530+ - ![ id] ( https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Indonesia.png ) ** Indonesia** :
2531+ [ andirkh/clean-code-javascript/] ( https://github.com/andirkh/clean-code-javascript/ )
2532+ - ![ it] ( https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Italy.png ) ** Italian** :
2533+ [ frappacchio/clean-code-javascript/] ( https://github.com/frappacchio/clean-code-javascript/ )
25372534
25382535** [ ⬆ back to top] ( #table-of-contents ) **
0 commit comments